-
Notifications
You must be signed in to change notification settings - Fork 38
feat(checkout): Migrate to v2 sanction API and add token info #2670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
2d41268
ea81125
e549752
2a332f3
0a18d90
389da8a
26ac3b5
754805f
094778b
65f1387
dd6fa2d
ffeba32
3c4ee62
4fa0fb8
24141fd
3d2e8c2
8f5d2b1
5917288
99194c6
df4292b
da53818
d51ca86
94a4ceb
0671d68
698ff0e
72aed4f
265cb8a
f0c9eca
62c0846
d689bb3
0d11549
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,9 +22,17 @@ export type AssessmentResult = { | |
| }; | ||
| }; | ||
|
|
||
| // New type for v2 request items | ||
| type SanctionsCheckV2RequestItem = { | ||
| address: string; | ||
| amount: string; | ||
| token_addr: string; | ||
| }; | ||
|
|
||
| export const fetchRiskAssessment = async ( | ||
| addresses: string[], | ||
| config: CheckoutConfiguration, | ||
| tokenData: Array<{ address: string; tokenAddr: string; amount: string }>, | ||
| ): Promise<AssessmentResult> => { | ||
| const result = Object.fromEntries( | ||
| addresses.map((address) => [address.toLowerCase(), { sanctioned: false }]), | ||
|
|
@@ -41,11 +49,27 @@ export const fetchRiskAssessment = async ( | |
| try { | ||
| const riskLevels = riskConfig?.levels.map((l) => l.toLowerCase()) ?? []; | ||
|
|
||
| // Prepare v2 request payload | ||
| const requestPayload: SanctionsCheckV2RequestItem[] = addresses.map((address) => { | ||
| const item: SanctionsCheckV2RequestItem = { | ||
| address, | ||
| token_addr: '', | ||
| amount: '0', | ||
| }; | ||
|
|
||
| // Add token and amount data | ||
| const tokenInfo = tokenData.find((t) => t.address.toLowerCase() === address.toLowerCase()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like if tokenInfo can't be found, we'll send to the API.. what will happen? Will this cause an error for the user?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the token_addr and amount are not used in determining the risk level actually so there should not be any impact, but let me update the logic here to only call api when token info's valid |
||
| if (tokenInfo) { | ||
| item.token_addr = tokenInfo.tokenAddr; | ||
| item.amount = tokenInfo.amount; | ||
| } | ||
|
|
||
| return item; | ||
| }); | ||
|
|
||
| const response = await axios.post<RiskAssessment[]>( | ||
| `${IMMUTABLE_API_BASE_URL[config.environment]}/v1/sanctions/check`, | ||
| { | ||
| addresses, | ||
| }, | ||
| `${IMMUTABLE_API_BASE_URL[config.environment]}/v2/sanctions/check`, | ||
| requestPayload, | ||
| ); | ||
|
|
||
| for (const assessment of response.data) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -425,7 +425,15 @@ export function AddTokens({ | |
| const sendRequestOnRampEvent = async () => { | ||
| if ( | ||
| toAddress | ||
| && (await checkSanctionedAddresses([toAddress], checkout.config)) | ||
| && (await checkSanctionedAddresses( | ||
| [toAddress], | ||
| checkout.config, | ||
| [{ | ||
| address: toAddress, | ||
| tokenAddr: selectedToken?.address || '', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be checking that a token has been selected before calling this - rather than going ahead with the empty string?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep good callout, updated |
||
| amount: selectedAmount || '0', | ||
| }], | ||
| )) | ||
| ) { | ||
| viewDispatch({ | ||
| payload: { | ||
|
|
@@ -502,6 +510,18 @@ export function AddTokens({ | |
| && (await checkSanctionedAddresses( | ||
| [fromAddress, toAddress], | ||
| checkout.config, | ||
| [ | ||
| { | ||
| address: fromAddress, | ||
| tokenAddr: selectedToken?.address || '', | ||
| amount: selectedAmount || '0', | ||
| }, | ||
| { | ||
| address: toAddress, | ||
| tokenAddr: selectedToken?.address || '', | ||
| amount: selectedAmount || '0', | ||
| }, | ||
| ], | ||
| )) | ||
| ) { | ||
| viewDispatch({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
addresshere the same as the address isaddresses- can we remove one of them so that the caller doesn't have the provide the same info twice?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep will update