Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/kyc-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `KycService.getStep` returns `reasons`, the retry codes from `GET /vendors/{vendor}/step`. The list is empty unless `status` is `retry`, and an older kyc-api that omits the field reads as `[]` ([#11914](https://github.com/MetaMask/core/pull/11914))
- `OnboardingVendorState.reasons` stores those codes while `status` is `retry` and is cleared otherwise ([#11914](https://github.com/MetaMask/core/pull/11914))
- Add `kycConsumer` to `KycDisclaimersCatalog` and `KycSessionDisclaimers`, plus the `KycConsumerDocument` type. `KycService.fetchSessionDisclaimersByCountry` and `fetchSessionDisclaimersBySessionId` validate the field as required, so a response without it is rejected as malformed ([#11918](https://github.com/MetaMask/core/pull/11918))
- `KycService.submitSessionDisclaimers` takes an optional `kycConsumer` list and posts it with the idOS and identity provider consents. An empty list is sent as `[]` ([#11918](https://github.com/MetaMask/core/pull/11918))
- `VendorOnboardingController` state gains `country` per vendor (the country the terms page loaded, not the residence country), and `acceptedDisclaimerIds` is now `string[] | undefined`: `undefined` means the user has not agreed and `[]` means they agreed to a catalog with no documents. The step read sends `acceptedDisclaimerIds` whenever it is defined, as an empty value for `[]` (`acceptedDisclaimerIds=`), and omits it when it is undefined. Saved state with accepted terms but no `country` is reset to undefined when the controller starts ([#11918](https://github.com/MetaMask/core/pull/11918))
Expand Down
83 changes: 80 additions & 3 deletions packages/kyc-controller/src/KycService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,7 @@ describe('KycService', () => {
step: 'mfa',
status: 'none',
sessionId: null,
reasons: [],
});
});

Expand All @@ -1157,7 +1158,12 @@ describe('KycService', () => {
await service.getStep('kalshi', {
acceptedDisclaimerIds: ['tos-v1', 'privacy-v1'],
}),
).toStrictEqual({ step: 'mfa', status: 'none', sessionId: null });
).toStrictEqual({
step: 'mfa',
status: 'none',
sessionId: null,
reasons: [],
});
});

it("returns the vendor's relay session id", async () => {
Expand All @@ -1173,9 +1179,69 @@ describe('KycService', () => {
step: 'sumsub',
status: 'none',
sessionId: 'relay-session-1',
reasons: [],
});
});

it('returns the retry reasons kyc-api sends', async () => {
nock(MOCK_API_URL)
.get('/vendors/kalshi/step')
.reply(200, {
vendor: 'kalshi',
step: 'sumsub',
status: 'retry',
sessionId: 'relay-session-1',
reasons: ['invalid_address', 'poa_required'],
});
const { service } = getService();

expect(await service.getStep('kalshi')).toStrictEqual({
step: 'sumsub',
status: 'retry',
sessionId: 'relay-session-1',
reasons: ['invalid_address', 'poa_required'],
});
});

it.each(['none', 'pending', 'approved', 'rejected', 'unrecognised'])(
'returns no reasons for the %s status even when kyc-api sends some',
async (status) => {
nock(MOCK_API_URL)
.get('/vendors/kalshi/step')
.reply(200, {
vendor: 'kalshi',
step: 'sumsub',
status,
sessionId: 'relay-session-1',
reasons: ['invalid_address'],
});
const { service } = getService();

expect((await service.getStep('kalshi')).reasons).toMatchInlineSnapshot(
`[]`,
);
},
);

it('returns no reasons for a retry answer that omits them', async () => {
nock(MOCK_API_URL).get('/vendors/kalshi/step').reply(200, {
vendor: 'kalshi',
step: 'sumsub',
status: 'retry',
sessionId: 'relay-session-1',
});
const { service } = getService();

expect(await service.getStep('kalshi')).toMatchInlineSnapshot(`
{
"reasons": [],
"sessionId": "relay-session-1",
"status": "retry",
"step": "sumsub",
}
`);
});

it('returns a null session id when kyc-api omits it', async () => {
nock(MOCK_API_URL)
.get('/vendors/kalshi/step')
Expand Down Expand Up @@ -1265,10 +1331,20 @@ describe('KycService', () => {

expect(
await service.getStep('kalshi', { mfaCompleted: true }),
).toStrictEqual({ step: 'terms', status: 'none', sessionId: null });
).toStrictEqual({
step: 'terms',
status: 'none',
sessionId: null,
reasons: [],
});
expect(
await service.getStep('iron', { vendorTermsAcceptedLocally: true }),
).toStrictEqual({ step: 'mfa', status: 'none', sessionId: null });
).toStrictEqual({
step: 'mfa',
status: 'none',
sessionId: null,
reasons: [],
});
});

it('ignores a field kyc-api adds that this version does not know', async () => {
Expand All @@ -1284,6 +1360,7 @@ describe('KycService', () => {
step: 'kalshi_email_link',
status: 'pending',
sessionId: null,
reasons: [],
});
});

Expand Down
7 changes: 5 additions & 2 deletions packages/kyc-controller/src/KycService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ const StepResponseStruct = type({
step: string(),
status: string(),
sessionId: optional(nullable(string())),
reasons: optional(array(string())),
});

const CreateSessionResponseStruct = type({ sessionToken: string() });
Expand Down Expand Up @@ -1203,15 +1204,17 @@ export class KycService extends BaseDataService<
url.searchParams.set('mfaCompleted', 'true');
}
const data = await this.#requestJson(url, { method: 'GET' });
const { step, status, sessionId } = this.#validateResponse(
const { step, status, sessionId, reasons } = this.#validateResponse(
data,
StepResponseStruct,
'vendor step',
);
const knownStatus = toKycStepStatus(status);
return {
step: toKycStep(step),
status: toKycStepStatus(status),
status: knownStatus,
sessionId: sessionId ?? null,
reasons: knownStatus === 'retry' ? (reasons ?? []) : [],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems odd for us to check knownStatus === 'retry' here. We probably need to use reasons for rejection as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we are purposefully not showing any reasons on the rejected screen. But I'm happy to remove this gate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, but this should be an API level concern in that case? I won't block on this

};
}

Expand Down
Loading