Skip to content

Commit 0a18d90

Browse files
committed
Mark token info as non-optional in v2 sanction
1 parent 2a332f3 commit 0a18d90

8 files changed

Lines changed: 52 additions & 48 deletions

File tree

packages/checkout/sdk/src/riskAssessment/riskAssessment.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ export type AssessmentResult = {
2424

2525
// New type for v2 request items
2626
type SanctionsCheckV2RequestItem = {
27-
address?: string;
28-
amount?: string;
29-
token_addr?: string;
27+
address: string;
28+
amount: string;
29+
token_addr: string;
3030
};
3131

3232
export const fetchRiskAssessment = async (
3333
addresses: string[],
3434
config: CheckoutConfiguration,
35-
tokenData?: Array<{ address: string; tokenAddr?: string; amount?: string }>,
35+
tokenData: Array<{ address: string; tokenAddr: string; amount: string }>,
3636
): Promise<AssessmentResult> => {
3737
const result = Object.fromEntries(
3838
addresses.map((address) => [address.toLowerCase(), { sanctioned: false }]),
@@ -51,15 +51,17 @@ export const fetchRiskAssessment = async (
5151

5252
// Prepare v2 request payload
5353
const requestPayload: SanctionsCheckV2RequestItem[] = addresses.map((address) => {
54-
const item: SanctionsCheckV2RequestItem = { address };
55-
56-
// Add token and amount data if available
57-
if (tokenData) {
58-
const tokenInfo = tokenData.find((t) => t.address.toLowerCase() === address.toLowerCase());
59-
if (tokenInfo) {
60-
if (tokenInfo.tokenAddr) item.token_addr = tokenInfo.tokenAddr;
61-
if (tokenInfo.amount) item.amount = tokenInfo.amount;
62-
}
54+
const item: SanctionsCheckV2RequestItem = {
55+
address,
56+
token_addr: '',
57+
amount: '0'
58+
};
59+
60+
// Add token and amount data
61+
const tokenInfo = tokenData.find((t) => t.address.toLowerCase() === address.toLowerCase());
62+
if (tokenInfo) {
63+
item.token_addr = tokenInfo.tokenAddr;
64+
item.amount = tokenInfo.amount;
6365
}
6466

6567
return item;

packages/checkout/sdk/src/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,12 @@ export class Checkout {
228228
/**
229229
* Fetches risk assessment for the given addresses.
230230
* @param {string[]} addresses - The addresses to assess.
231-
* @param {Array<{address: string; tokenAddr?: string; amount?: string}>} [tokenData] - Optional token and amount data for each address.
231+
* @param {Array<{address: string; tokenAddr: string; amount: string}>} tokenData - Required token and amount data for each address.
232232
* @returns {Promise<AssessmentResult>} - A promise that resolves to the risk assessment result.
233233
*/
234234
public async getRiskAssessment(
235235
addresses: string[],
236-
tokenData?: Array<{ address: string; tokenAddr?: string; amount?: string }>,
236+
tokenData: Array<{ address: string; tokenAddr: string; amount: string }>,
237237
): Promise<AssessmentResult> {
238238
return await fetchRiskAssessment(addresses, this.config, tokenData);
239239
}

packages/checkout/widgets-lib/src/functions/checkSanctionedAddresses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
export const checkSanctionedAddresses = async (
88
addresses: string[],
99
config: CheckoutConfiguration,
10-
tokenData?: Array<{ address: string; tokenAddr?: string; amount?: string }>,
10+
tokenData: Array<{ address: string; tokenAddr: string; amount: string }>,
1111
): Promise<boolean> => {
1212
const result = await fetchRiskAssessment(addresses, config, tokenData);
1313
return isAddressSanctioned(result, undefined);

packages/checkout/widgets-lib/src/widgets/add-tokens/views/AddTokens.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,11 @@ export function AddTokens({
428428
&& (await checkSanctionedAddresses(
429429
[toAddress],
430430
checkout.config,
431-
selectedToken?.address && selectedAmount ? [{
431+
[{
432432
address: toAddress,
433-
tokenAddr: selectedToken.address,
434-
amount: selectedAmount,
435-
}] : undefined,
433+
tokenAddr: selectedToken?.address || '',
434+
amount: selectedAmount || '0',
435+
}],
436436
))
437437
) {
438438
viewDispatch({
@@ -510,18 +510,18 @@ export function AddTokens({
510510
&& (await checkSanctionedAddresses(
511511
[fromAddress, toAddress],
512512
checkout.config,
513-
selectedToken?.address && selectedAmount ? [
513+
[
514514
{
515515
address: fromAddress,
516-
tokenAddr: selectedToken.address,
517-
amount: selectedAmount,
516+
tokenAddr: selectedToken?.address || '',
517+
amount: selectedAmount || '0',
518518
},
519519
{
520520
address: toAddress,
521-
tokenAddr: selectedToken.address,
522-
amount: selectedAmount,
521+
tokenAddr: selectedToken?.address || '',
522+
amount: selectedAmount || '0',
523523
},
524-
] : undefined,
524+
],
525525
))
526526
) {
527527
viewDispatch({

packages/checkout/widgets-lib/src/widgets/bridge/components/BridgeForm.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,19 @@ export function BridgeForm(props: BridgeFormProps) {
188188
addresses.push(to.walletAddress);
189189
}
190190

191-
// Prepare token data for v2 API if available
192-
const tokenData = formToken && formAmount ? [
191+
// Prepare token data for v2 API - now required
192+
const tokenData = [
193193
{
194194
address: from.walletAddress,
195-
tokenAddr: formToken.token.address,
196-
amount: formAmount,
195+
tokenAddr: formToken?.token.address || '',
196+
amount: formAmount || '0',
197197
},
198198
...(to.walletAddress.toLowerCase() !== from.walletAddress.toLowerCase() ? [{
199199
address: to.walletAddress,
200-
tokenAddr: formToken.token.address,
201-
amount: formAmount,
200+
tokenAddr: formToken?.token.address || '',
201+
amount: formAmount || '0',
202202
}] : []),
203-
] : undefined;
203+
];
204204

205205
const assessment = await fetchRiskAssessment(addresses, checkout.config, tokenData);
206206
bridgeDispatch({

packages/checkout/widgets-lib/src/widgets/on-ramp/views/OnRampMain.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ export function OnRampMain({
231231
(async () => {
232232
const walletAddress = await (await provider.getSigner()).getAddress();
233233

234-
// Prepare token data for v2 API if available
235-
const tokenData = tokenAddress && tokenAmount ? [{
234+
// Prepare token data for v2 API - now required
235+
const tokenData = [{
236236
address: walletAddress,
237-
tokenAddr: tokenAddress,
238-
amount: tokenAmount,
239-
}] : undefined;
237+
tokenAddr: tokenAddress || '',
238+
amount: tokenAmount || '0',
239+
}];
240240

241241
const assessment = await fetchRiskAssessment([walletAddress], checkout.config, tokenData);
242242

packages/checkout/widgets-lib/src/widgets/sale/context/SaleContextProvider.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,15 @@ export function SaleContextProvider(props: {
257257
return;
258258
}
259259

260-
// Prepare token data for v2 API if available
260+
// Prepare token data for v2 API - now required
261261
// Use selectedCurrency and orderQuote to get token address and amount when they exist
262-
const tokenData = selectedCurrency?.address && orderQuote.totalAmount[selectedCurrency.name] ? [{
262+
const tokenData = [{
263263
address,
264-
tokenAddr: selectedCurrency.address,
265-
amount: orderQuote.totalAmount[selectedCurrency.name].amount.toString(),
266-
}] : undefined;
264+
tokenAddr: selectedCurrency?.address || '',
265+
amount: (selectedCurrency?.address && orderQuote.totalAmount[selectedCurrency.name])
266+
? orderQuote.totalAmount[selectedCurrency.name].amount.toString()
267+
: '0',
268+
}];
267269

268270
const assessment = await fetchRiskAssessment([address], checkout.config, tokenData);
269271
setRiskAssessment(assessment);

packages/checkout/widgets-lib/src/widgets/swap/SwapWidget.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ export default function SwapWidget({
205205
return;
206206
}
207207

208-
// Prepare token data for v2 API if available
209-
const tokenData = fromTokenAddress && amount ? [{
208+
// Prepare token data for v2 API - now required
209+
const tokenData = [{
210210
address,
211-
tokenAddr: fromTokenAddress,
212-
amount,
213-
}] : undefined;
211+
tokenAddr: fromTokenAddress || '',
212+
amount: amount || '0',
213+
}];
214214

215215
const assessment = await fetchRiskAssessment([address], checkout.config, tokenData);
216216
swapDispatch({

0 commit comments

Comments
 (0)