Skip to content
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

WT-1727 Update smart checkout output interfaces #924

Merged
merged 34 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
32b56a1
Route types
imx-mikhala Oct 2, 2023
e021d84
smart checkout tests
imx-mikhala Oct 2, 2023
8aa5a81
set passport true on router
imx-mikhala Oct 2, 2023
40898d2
update cancel endpoint
imx-mikhala Oct 2, 2023
2ddc64b
update buy endpoint
imx-mikhala Oct 2, 2023
8f471ee
update sell endpoint
imx-mikhala Oct 3, 2023
89571c5
switch order of sign msg and approvals in sell
imx-mikhala Oct 3, 2023
dd80268
fix bridge estimator tests
imx-mikhala Oct 3, 2023
d57d54f
fix buy tests
imx-mikhala Oct 3, 2023
0b49a9e
fix mock
imx-mikhala Oct 3, 2023
e41b8dd
Add type definitions
imx-mikhala Oct 3, 2023
900ad27
Merge branch 'main' into WT-1727
imx-mikhala Oct 3, 2023
2819409
Merge branch 'main' into WT-1727
imx-mikhala Oct 3, 2023
6d33513
fix types
imx-mikhala Oct 3, 2023
3a94a5e
Merge remote-tracking branch 'origin/WT-1727' into WT-1727
imx-mikhala Oct 3, 2023
65d672b
fix imports
imx-mikhala Oct 3, 2023
1299fbf
log results in sample app
imx-mikhala Oct 3, 2023
87b6400
log result of smart checkout
imx-mikhala Oct 3, 2023
5d932ed
remove routing calc log
imx-mikhala Oct 3, 2023
acb9419
update cancel
imx-mikhala Oct 4, 2023
0c65179
update buy
imx-mikhala Oct 4, 2023
abf4591
update sell
imx-mikhala Oct 4, 2023
5c84202
update checkout returns
imx-mikhala Oct 4, 2023
0c10f50
update type docs
imx-mikhala Oct 4, 2023
3c7cf25
Merge branch 'main' into WT-1727
imx-mikhala Oct 4, 2023
b4a672b
Merge branch 'main' into WT-1727
imx-mikhala Oct 4, 2023
50b75ed
use type
imx-mikhala Oct 4, 2023
6fd75b0
remove unused
imx-mikhala Oct 4, 2023
dd04172
Merge branch 'main' into WT-1727
imx-mikhala Oct 4, 2023
dc53caf
actions -> processes
imx-mikhala Oct 4, 2023
601b57e
update onramp
imx-mikhala Oct 4, 2023
56997f6
Merge branch 'main' into WT-1727
imx-mikhala Oct 4, 2023
0e48ab5
add types to export
imx-mikhala Oct 4, 2023
2e5d027
Merge remote-tracking branch 'origin/WT-1727' into WT-1727
imx-mikhala Oct 4, 2023
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
4 changes: 2 additions & 2 deletions packages/checkout/sdk-sample-app/src/components/Buy.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Checkout, BuyResult, BuyStatusType, BuyStatus } from '@imtbl/checkout-sdk';
import { Checkout } from '@imtbl/checkout-sdk';
import { Web3Provider } from '@ethersproject/providers';
import LoadingButton from './LoadingButton';
import { useEffect, useState } from 'react';
Expand Down Expand Up @@ -38,7 +38,7 @@ export default function Buy({ checkout, provider }: BuyProps) {
provider,
orders: [{id: orderId, takerFees: [{amount: {percentageDecimal: 0.01}, recipient: '0x96654086969DCaa88933E753Aa52d46EAB269Ff7'}]}],
});
console.log(buyResult);
console.log('Buy result', buyResult);
setLoading(false);
} catch (err: any) {
console.log(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ export default function Cancel({ checkout, provider }: CancelProps) {
setError(null);
setLoading(true);
try {
await checkout.cancel({
const result = await checkout.cancel({
provider,
orderIds: [orderId],
});
console.log('Cancel result', result);
setLoading(false);
} catch (err: any) {
setError(err);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Checkout, BuyResult, BuyStatusType, BuyStatus } from '@imtbl/checkout-sdk';
import { Checkout } from '@imtbl/checkout-sdk';
import { Web3Provider } from '@ethersproject/providers';
import LoadingButton from './LoadingButton';
import { useEffect, useState } from 'react';
Expand Down
3 changes: 2 additions & 1 deletion packages/checkout/sdk-sample-app/src/components/Sell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ export default function Sell({ checkout, provider }: SellProps) {
}]
}]

await checkout.sell({
const result = await checkout.sell({
provider,
orders,
});
console.log('Sell result', result);
setLoading(false);
} catch (err: any) {
setError(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ export const SmartCheckoutForm = ({ checkout, provider }: SmartCheckoutProps) =>
setLoading(true);

try {
checkout.smartCheckout(
const result = await checkout.smartCheckout(
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nice, I noticed the await in my current branch, def helps with the loading state!

{
provider,
itemRequirements,
transactionOrGasAmount,
}
);
console.log('Smart checkout result', result);
setLoading(false);
setSuccess(true);
} catch (err: any) {
Expand Down
20 changes: 12 additions & 8 deletions packages/checkout/sdk/src/Checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ import {
TokenFilterTypes,
OnRampProviderFees,
FiatRampParams,
SmartCheckoutResult,
CancelResult,
BuyResult,
SellResult,
} from './types';
import { CheckoutConfiguration } from './config';
import { createReadOnlyProviders } from './readOnlyProviders/readOnlyProvider';
Expand Down Expand Up @@ -282,7 +286,7 @@ export class Checkout {
*/
public async buy(
params: BuyParams,
): Promise<void> {
): Promise<BuyResult> {
if (this.config.isProduction) {
throw new Error('This endpoint is not currently available.');
}
Expand All @@ -300,7 +304,7 @@ export class Checkout {
params.provider,
);

await buy.buy(this.config, web3Provider, params.orders);
return await buy.buy(this.config, web3Provider, params.orders);
}

/**
Expand All @@ -311,7 +315,7 @@ export class Checkout {
*/
public async sell(
params: SellParams,
): Promise<void> {
): Promise<SellResult> {
if (this.config.isProduction) {
throw new Error('This endpoint is not currently available.');
}
Expand All @@ -329,7 +333,7 @@ export class Checkout {
params.provider,
);

await sell.sell(
return await sell.sell(
this.config,
web3Provider,
params.orders,
Expand All @@ -342,7 +346,7 @@ export class Checkout {
*/
public async cancel(
params: CancelParams,
): Promise<void> {
): Promise<CancelResult> {
if (this.config.isProduction) {
throw new Error('This endpoint is not currently available.');
}
Expand All @@ -358,7 +362,7 @@ export class Checkout {
params.provider,
);

await cancel.cancel(this.config, web3Provider, params.orderIds);
return await cancel.cancel(this.config, web3Provider, params.orderIds);
}

/**
Expand All @@ -367,7 +371,7 @@ export class Checkout {
*/
public async smartCheckout(
params: SmartCheckoutParams,
): Promise<void> {
): Promise<SmartCheckoutResult> {
if (this.config.isProduction) {
throw new Error('This endpoint is not currently available.');
}
Expand All @@ -387,7 +391,7 @@ export class Checkout {
throw new CheckoutError('Failed to map item requirements', CheckoutErrorType.ITEM_REQUIREMENTS_ERROR);
}

await smartCheckout.smartCheckout(
return await smartCheckout.smartCheckout(
this.config,
web3Provider,
itemRequirements,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Environment } from '@imtbl/config';
import { BigNumber } from 'ethers';
import { CheckoutConfiguration } from '../../config';
import {
allowListCheck, allowListCheckForBridge, allowListCheckForOnRamp, allowListCheckForSwap,
allowListCheck,
allowListCheckForBridge,
allowListCheckForOnRamp,
allowListCheckForSwap,
} from './allowListCheck';
import {
BridgeConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CheckoutConfiguration, getL1ChainId, getL2ChainId } from '../../config'
import {
BridgeConfig,
DexConfig, OnRampConfig,
RoutingOptionsAvailable,
AvailableRoutingOptions,
TokenInfo,
} from '../../types';
import { TokenBalanceResult, TokenBalances } from '../routing/types';
Expand All @@ -23,7 +23,7 @@ const filterTokens = (allowedTokens: TokenInfo[], balances: TokenBalanceResult |

export const allowListCheckForOnRamp = async (
config: CheckoutConfiguration,
availableRoutingOptions: RoutingOptionsAvailable,
availableRoutingOptions: AvailableRoutingOptions,
) : Promise<OnRampTokensAllowList> => {
if (availableRoutingOptions.onRamp) {
const onRampOptions = await config.remote.getConfig('onramp') as OnRampConfig;
Expand All @@ -42,7 +42,7 @@ export const allowListCheckForOnRamp = async (
export const allowListCheckForBridge = async (
config: CheckoutConfiguration,
tokenBalances: TokenBalances,
availableRoutingOptions: RoutingOptionsAvailable,
availableRoutingOptions: AvailableRoutingOptions,
) : Promise<TokenInfo[]> => {
if (availableRoutingOptions.bridge) {
const allowedTokens = ((await config.remote.getConfig('bridge')) as BridgeConfig)?.tokens ?? [];
Expand All @@ -56,7 +56,7 @@ export const allowListCheckForBridge = async (
export const allowListCheckForSwap = async (
config: CheckoutConfiguration,
tokenBalances: TokenBalances,
availableRoutingOptions: RoutingOptionsAvailable,
availableRoutingOptions: AvailableRoutingOptions,
) : Promise<TokenInfo[]> => {
if (availableRoutingOptions.swap) {
const allowedTokens = ((await config.remote.getConfig('dex')) as DexConfig)?.tokens ?? [];
Expand All @@ -73,7 +73,7 @@ export const allowListCheckForSwap = async (
export const allowListCheck = async (
config: CheckoutConfiguration,
tokenBalances: TokenBalances,
availableRoutingOptions: RoutingOptionsAvailable,
availableRoutingOptions: AvailableRoutingOptions,
) : Promise<RoutingTokensAllowList> => {
const tokenAllowList: RoutingTokensAllowList = {};
tokenAllowList.swap = await allowListCheckForSwap(config, tokenBalances, availableRoutingOptions);
Expand Down
Loading