Skip to content

Commit 2a46fe0

Browse files
authored
WT-1727 Update smart checkout output interfaces (#924)
1 parent ca1a947 commit 2a46fe0

37 files changed

+2305
-1460
lines changed

packages/checkout/sdk-sample-app/src/components/Buy.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Checkout, BuyResult, BuyStatusType, BuyStatus } from '@imtbl/checkout-sdk';
1+
import { Checkout } from '@imtbl/checkout-sdk';
22
import { Web3Provider } from '@ethersproject/providers';
33
import LoadingButton from './LoadingButton';
44
import { useEffect, useState } from 'react';
@@ -38,7 +38,7 @@ export default function Buy({ checkout, provider }: BuyProps) {
3838
provider,
3939
orders: [{id: orderId, takerFees: [{amount: {percentageDecimal: 0.01}, recipient: '0x96654086969DCaa88933E753Aa52d46EAB269Ff7'}]}],
4040
});
41-
console.log(buyResult);
41+
console.log('Buy result', buyResult);
4242
setLoading(false);
4343
} catch (err: any) {
4444
console.log(err);

packages/checkout/sdk-sample-app/src/components/Cancel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ export default function Cancel({ checkout, provider }: CancelProps) {
3333
setError(null);
3434
setLoading(true);
3535
try {
36-
await checkout.cancel({
36+
const result = await checkout.cancel({
3737
provider,
3838
orderIds: [orderId],
3939
});
40+
console.log('Cancel result', result);
4041
setLoading(false);
4142
} catch (err: any) {
4243
setError(err);

packages/checkout/sdk-sample-app/src/components/Listings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Checkout, BuyResult, BuyStatusType, BuyStatus } from '@imtbl/checkout-sdk';
1+
import { Checkout } from '@imtbl/checkout-sdk';
22
import { Web3Provider } from '@ethersproject/providers';
33
import LoadingButton from './LoadingButton';
44
import { useEffect, useState } from 'react';

packages/checkout/sdk-sample-app/src/components/Sell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,11 @@ export default function Sell({ checkout, provider }: SellProps) {
9191
}]
9292
}]
9393

94-
await checkout.sell({
94+
const result = await checkout.sell({
9595
provider,
9696
orders,
9797
});
98+
console.log('Sell result', result);
9899
setLoading(false);
99100
} catch (err: any) {
100101
setError(err);

packages/checkout/sdk-sample-app/src/components/SmartCheckoutForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,14 @@ export const SmartCheckoutForm = ({ checkout, provider }: SmartCheckoutProps) =>
131131
setLoading(true);
132132

133133
try {
134-
checkout.smartCheckout(
134+
const result = await checkout.smartCheckout(
135135
{
136136
provider,
137137
itemRequirements,
138138
transactionOrGasAmount,
139139
}
140140
);
141+
console.log('Smart checkout result', result);
141142
setLoading(false);
142143
setSuccess(true);
143144
} catch (err: any) {

packages/checkout/sdk/src/Checkout.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ import {
4848
TokenFilterTypes,
4949
OnRampProviderFees,
5050
FiatRampParams,
51+
SmartCheckoutResult,
52+
CancelResult,
53+
BuyResult,
54+
SellResult,
5155
} from './types';
5256
import { CheckoutConfiguration } from './config';
5357
import { createReadOnlyProviders } from './readOnlyProviders/readOnlyProvider';
@@ -282,7 +286,7 @@ export class Checkout {
282286
*/
283287
public async buy(
284288
params: BuyParams,
285-
): Promise<void> {
289+
): Promise<BuyResult> {
286290
if (this.config.isProduction) {
287291
throw new Error('This endpoint is not currently available.');
288292
}
@@ -292,15 +296,15 @@ export class Checkout {
292296

293297
if (params.orders.length > 1) {
294298
// eslint-disable-next-line no-console
295-
console.warn('This endpoint currently only actions the first order in the array.');
299+
console.warn('This endpoint currently only processes the first order in the array.');
296300
}
297301

298302
const web3Provider = await provider.validateProvider(
299303
this.config,
300304
params.provider,
301305
);
302306

303-
await buy.buy(this.config, web3Provider, params.orders);
307+
return await buy.buy(this.config, web3Provider, params.orders);
304308
}
305309

306310
/**
@@ -311,7 +315,7 @@ export class Checkout {
311315
*/
312316
public async sell(
313317
params: SellParams,
314-
): Promise<void> {
318+
): Promise<SellResult> {
315319
if (this.config.isProduction) {
316320
throw new Error('This endpoint is not currently available.');
317321
}
@@ -321,15 +325,15 @@ export class Checkout {
321325

322326
if (params.orders.length > 1) {
323327
// eslint-disable-next-line no-console
324-
console.warn('This endpoint currently only actions the first order in the array.');
328+
console.warn('This endpoint currently only processes the first order in the array.');
325329
}
326330

327331
const web3Provider = await provider.validateProvider(
328332
this.config,
329333
params.provider,
330334
);
331335

332-
await sell.sell(
336+
return await sell.sell(
333337
this.config,
334338
web3Provider,
335339
params.orders,
@@ -342,7 +346,7 @@ export class Checkout {
342346
*/
343347
public async cancel(
344348
params: CancelParams,
345-
): Promise<void> {
349+
): Promise<CancelResult> {
346350
if (this.config.isProduction) {
347351
throw new Error('This endpoint is not currently available.');
348352
}
@@ -351,14 +355,14 @@ export class Checkout {
351355
console.warn('This endpoint is currently under construction.');
352356

353357
// eslint-disable-next-line no-console
354-
console.warn('This endpoint currently only actions the first order in the array.');
358+
console.warn('This endpoint currently only processes the first order in the array.');
355359

356360
const web3Provider = await provider.validateProvider(
357361
this.config,
358362
params.provider,
359363
);
360364

361-
await cancel.cancel(this.config, web3Provider, params.orderIds);
365+
return await cancel.cancel(this.config, web3Provider, params.orderIds);
362366
}
363367

364368
/**
@@ -367,7 +371,7 @@ export class Checkout {
367371
*/
368372
public async smartCheckout(
369373
params: SmartCheckoutParams,
370-
): Promise<void> {
374+
): Promise<SmartCheckoutResult> {
371375
if (this.config.isProduction) {
372376
throw new Error('This endpoint is not currently available.');
373377
}
@@ -387,7 +391,7 @@ export class Checkout {
387391
throw new CheckoutError('Failed to map item requirements', CheckoutErrorType.ITEM_REQUIREMENTS_ERROR);
388392
}
389393

390-
await smartCheckout.smartCheckout(
394+
return await smartCheckout.smartCheckout(
391395
this.config,
392396
web3Provider,
393397
itemRequirements,

packages/checkout/sdk/src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export {
33
ChainId,
44
ChainName,
55
CHECKOUT_API_BASE_URL,
6+
CheckoutStatus,
67
ExchangeType,
78
GasEstimateType,
89
GasTokenType,
@@ -15,24 +16,30 @@ export {
1516
} from './types';
1617
export type {
1718
AllowedNetworkConfig,
19+
BuyOrder,
1820
BuyParams,
1921
BuyResult,
22+
BuyToken,
2023
CancelParams,
24+
CancelResult,
2125
CheckConnectionParams,
2226
CheckConnectionResult,
2327
CheckoutModuleConfiguration,
2428
ConnectParams,
2529
ConnectResult,
30+
DexConfig,
2631
ERC20ItemRequirement,
2732
ERC721ItemRequirement,
28-
FiatRampParams,
29-
DexConfig,
3033
FeePercentage,
3134
FeeToken,
35+
FiatRampParams,
36+
FulfillmentTransaction,
37+
GasAmount,
3238
GasEstimateBridgeToL2Result,
3339
GasEstimateParams,
3440
GasEstimateSwapResult,
3541
GasEstimateTokenConfig,
42+
GasToken,
3643
GetAllBalancesParams,
3744
GetAllBalancesResult,
3845
GetBalanceParams,
@@ -50,8 +57,8 @@ export type {
5057
NetworkInfo,
5158
OrderFee,
5259
RemoteConfiguration,
53-
SellParams,
5460
SellOrder,
61+
SellParams,
5562
SellResult,
5663
SellToken,
5764
SendTransactionParams,

packages/checkout/sdk/src/smartCheckout/allowList/allowListCheck.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { Environment } from '@imtbl/config';
22
import { BigNumber } from 'ethers';
33
import { CheckoutConfiguration } from '../../config';
44
import {
5-
allowListCheck, allowListCheckForBridge, allowListCheckForOnRamp, allowListCheckForSwap,
5+
allowListCheck,
6+
allowListCheckForBridge,
7+
allowListCheckForOnRamp,
8+
allowListCheckForSwap,
69
} from './allowListCheck';
710
import {
811
BridgeConfig,

packages/checkout/sdk/src/smartCheckout/allowList/allowListCheck.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { CheckoutConfiguration, getL1ChainId, getL2ChainId } from '../../config'
22
import {
33
BridgeConfig,
44
DexConfig, OnRampConfig,
5-
RoutingOptionsAvailable,
5+
AvailableRoutingOptions,
66
TokenInfo,
77
} from '../../types';
88
import { TokenBalanceResult, TokenBalances } from '../routing/types';
@@ -23,7 +23,7 @@ const filterTokens = (allowedTokens: TokenInfo[], balances: TokenBalanceResult |
2323

2424
export const allowListCheckForOnRamp = async (
2525
config: CheckoutConfiguration,
26-
availableRoutingOptions: RoutingOptionsAvailable,
26+
availableRoutingOptions: AvailableRoutingOptions,
2727
) : Promise<OnRampTokensAllowList> => {
2828
if (availableRoutingOptions.onRamp) {
2929
const onRampOptions = await config.remote.getConfig('onramp') as OnRampConfig;
@@ -42,7 +42,7 @@ export const allowListCheckForOnRamp = async (
4242
export const allowListCheckForBridge = async (
4343
config: CheckoutConfiguration,
4444
tokenBalances: TokenBalances,
45-
availableRoutingOptions: RoutingOptionsAvailable,
45+
availableRoutingOptions: AvailableRoutingOptions,
4646
) : Promise<TokenInfo[]> => {
4747
if (availableRoutingOptions.bridge) {
4848
const allowedTokens = ((await config.remote.getConfig('bridge')) as BridgeConfig)?.tokens ?? [];
@@ -56,7 +56,7 @@ export const allowListCheckForBridge = async (
5656
export const allowListCheckForSwap = async (
5757
config: CheckoutConfiguration,
5858
tokenBalances: TokenBalances,
59-
availableRoutingOptions: RoutingOptionsAvailable,
59+
availableRoutingOptions: AvailableRoutingOptions,
6060
) : Promise<TokenInfo[]> => {
6161
if (availableRoutingOptions.swap) {
6262
const allowedTokens = ((await config.remote.getConfig('dex')) as DexConfig)?.tokens ?? [];
@@ -73,7 +73,7 @@ export const allowListCheckForSwap = async (
7373
export const allowListCheck = async (
7474
config: CheckoutConfiguration,
7575
tokenBalances: TokenBalances,
76-
availableRoutingOptions: RoutingOptionsAvailable,
76+
availableRoutingOptions: AvailableRoutingOptions,
7777
) : Promise<RoutingTokensAllowList> => {
7878
const tokenAllowList: RoutingTokensAllowList = {};
7979
tokenAllowList.swap = await allowListCheckForSwap(config, tokenBalances, availableRoutingOptions);

0 commit comments

Comments
 (0)