Skip to content

Commit

Permalink
WT-1787 Update exports and return only one smart checkout result inst…
Browse files Browse the repository at this point in the history
…ead of array (#965)
  • Loading branch information
imx-mikhala committed Oct 11, 2023
1 parent e6473c0 commit 238134e
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 56 deletions.
23 changes: 20 additions & 3 deletions packages/checkout/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,33 @@ export type {
AllowedNetworkConfig,
AvailableRoutingOptions,
BalanceDelta,
BridgeFundingStep,
BuyOrder,
BuyParams,
BuyResult,
BuyResultFailed,
BuyResultInsufficientFunds,
BuyResultSuccess,
BuyToken,
CancelParams,
CancelResult,
CancelResultFailed,
CancelResultSuccess,
CheckConnectionParams,
CheckConnectionResult,
CheckoutModuleConfiguration,
ConnectParams,
ConnectResult,
DexConfig,
FeePercentage,
NativeItemRequirement,
ERC20ItemRequirement,
ERC721Balance,
ERC721ItemRequirement,
FeePercentage,
FeeToken,
FiatRampParams,
FulfillmentTransaction,
FundingItem,
FundingRoute,
FundingRouteFeeEstimate,
FundingStep,
GasAmount,
GasEstimateBridgeToL2Result,
Expand All @@ -61,22 +66,34 @@ export type {
GetWalletAllowListParams,
GetWalletAllowListResult,
ItemBalance,
NativeItemRequirement,
NetworkFilter,
NetworkInfo,
NoRouteOptions,
NoRoutesFound,
OnRampFundingStep,
OrderFee,
RemoteConfiguration,
RoutesFound,
RoutingOutcome,
SellOrder,
SellParams,
SellResult,
SellResultFailed,
SellResultInsufficientFunds,
SellResultSuccess,
SellToken,
SendTransactionParams,
SendTransactionResult,
SmartCheckoutInsufficient,
SmartCheckoutParams,
SmartCheckoutResult,
SmartCheckoutRouter,
SmartCheckoutSufficient,
SwapFundingStep,
SwitchNetworkParams,
SwitchNetworkResult,
TokenBalance,
TokenFilter,
TokenInfo,
TransactionRequirement,
Expand Down
14 changes: 7 additions & 7 deletions packages/checkout/sdk/src/smartCheckout/buy/buy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('buy', () => {

expect(buyResult).toEqual({
status: CheckoutStatus.SUCCESS,
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
});
expect(getUnsignedERC20ApprovalTransactions).toBeCalledTimes(1);
expect(getUnsignedFulfillmentTransactions).toBeCalledTimes(1);
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('buy', () => {
);
expect(buyResult).toEqual({
status: CheckoutStatus.SUCCESS,
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
});
expect(getUnsignedERC20ApprovalTransactions).toBeCalledTimes(1);
expect(getUnsignedFulfillmentTransactions).toBeCalledTimes(2);
Expand Down Expand Up @@ -745,7 +745,7 @@ describe('buy', () => {
expect(signFulfillmentTransactions).toBeCalledTimes(0);
expect(buyResult).toEqual({
status: CheckoutStatus.INSUFFICIENT_FUNDS,
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
});
});

Expand Down Expand Up @@ -857,7 +857,7 @@ describe('buy', () => {
status: CheckoutStatus.FAILED,
transactionHash: '0xHASH',
reason: 'approval error',
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
});
expect(getUnsignedERC20ApprovalTransactions).toBeCalledTimes(1);
expect(getUnsignedFulfillmentTransactions).toBeCalledTimes(1);
Expand Down Expand Up @@ -973,7 +973,7 @@ describe('buy', () => {
status: CheckoutStatus.FAILED,
transactionHash: '0xHASH',
reason: 'fulfillment error',
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
});
expect(getUnsignedERC20ApprovalTransactions).toBeCalledTimes(1);
expect(getUnsignedFulfillmentTransactions).toBeCalledTimes(1);
Expand Down Expand Up @@ -1296,7 +1296,7 @@ describe('buy', () => {
);
expect(buyResult).toEqual({
status: CheckoutStatus.SUCCESS,
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
});
expect(getUnsignedERC20ApprovalTransactions).toBeCalledTimes(1);
expect(getUnsignedFulfillmentTransactions).toBeCalledTimes(1);
Expand Down Expand Up @@ -1500,7 +1500,7 @@ describe('buy', () => {
);
expect(buyResult).toEqual({
status: CheckoutStatus.SUCCESS,
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
});
expect(getUnsignedERC20ApprovalTransactions).toBeCalledTimes(1);
expect(getUnsignedFulfillmentTransactions).toBeCalledTimes(1);
Expand Down
10 changes: 5 additions & 5 deletions packages/checkout/sdk/src/smartCheckout/buy/buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const buy = async (

if (orders.length === 0) {
throw new CheckoutError(
'No orders were passed in, must pass at least one order',
'No orders were provided to the orders array. Please provide at least one order.',
CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR,
);
}
Expand Down Expand Up @@ -215,7 +215,7 @@ export const buy = async (
status: CheckoutStatus.FAILED,
transactionHash: approvalResult.transactionHash,
reason: approvalResult.reason,
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
};
}

Expand All @@ -239,18 +239,18 @@ export const buy = async (
status: CheckoutStatus.FAILED,
transactionHash: fulfillmentResult.transactionHash,
reason: fulfillmentResult.reason,
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
};
}

return {
status: CheckoutStatus.SUCCESS,
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
};
}

return {
status: CheckoutStatus.INSUFFICIENT_FUNDS,
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
};
};
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/smartCheckout/cancel/cancel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const cancel = async (
let unsignedCancelOrderTransaction: PopulatedTransaction;
if (orderIds.length === 0) {
throw new CheckoutError(
'No orderIds were passed in, must pass at least one orderId to cancel',
'No orderIds were provided to the orderIds array. Please provide at least one orderId.',
CheckoutErrorType.CANCEL_ORDER_LISTING_ERROR,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,11 @@ describe('routingCalculator', () => {
fundingRoutes: [
{
priority: 1,
steps: [bridgeFundingStep],
steps: [swapFundingStep],
},
{
priority: 2,
steps: [swapFundingStep],
steps: [bridgeFundingStep],
},
{
priority: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,6 @@ export const routingCalculator = async (

let priority = 0;

if (bridgeFundingStep) {
priority++;
response.fundingRoutes.push({
priority,
steps: [bridgeFundingStep],
});
}

if (swapFundingSteps.length > 0) {
priority++;
swapFundingSteps.forEach((swapFundingStep) => {
Expand All @@ -338,6 +330,14 @@ export const routingCalculator = async (
});
}

if (bridgeFundingStep) {
priority++;
response.fundingRoutes.push({
priority,
steps: [bridgeFundingStep],
});
}

if (onRampFundingStep) {
priority++;
response.fundingRoutes.push({
Expand Down
12 changes: 6 additions & 6 deletions packages/checkout/sdk/src/smartCheckout/sell/sell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ describe('sell', () => {
);

expect(result).toEqual({
smartCheckoutResult: [{
smartCheckoutResult: {
sufficient: true,
transactionRequirements: [erc721TransactionRequirement],
}],
},
status: CheckoutStatus.SUCCESS,
orderIds: ['1234'],
});
Expand Down Expand Up @@ -307,10 +307,10 @@ describe('sell', () => {

expect(result).toEqual({
status: CheckoutStatus.INSUFFICIENT_FUNDS,
smartCheckoutResult: [{
smartCheckoutResult: {
sufficient: false,
transactionRequirements: [erc721TransactionRequirement],
}],
},
});

expect(smartCheckout).toBeCalledWith(
Expand Down Expand Up @@ -432,10 +432,10 @@ describe('sell', () => {
);

expect(result).toEqual({
smartCheckoutResult: [{
smartCheckoutResult: {
sufficient: true,
transactionRequirements: [erc721TransactionRequirement],
}],
},
status: CheckoutStatus.FAILED,
transactionHash: '0xHASH',
reason: 'Approval transaction failed and was reverted',
Expand Down
8 changes: 4 additions & 4 deletions packages/checkout/sdk/src/smartCheckout/sell/sell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const sell = async (

if (orders.length === 0) {
throw new CheckoutError(
'No orders were parsed, must parse at least one order',
'No orders were provided to the orders array. Please provide at least one order.',
CheckoutErrorType.PREPARE_ORDER_LISTING_ERROR,
);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ export const sell = async (
status: CheckoutStatus.FAILED,
transactionHash: approvalResult.transactionHash,
reason: approvalResult.reason,
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
};
}

Expand Down Expand Up @@ -210,12 +210,12 @@ export const sell = async (
return {
status: CheckoutStatus.SUCCESS,
orderIds: [orderId],
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
};
}

return {
status: CheckoutStatus.INSUFFICIENT_FUNDS,
smartCheckoutResult: [smartCheckoutResult],
smartCheckoutResult,
};
};
5 changes: 0 additions & 5 deletions packages/checkout/sdk/src/smartCheckout/smartCheckout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ describe('smartCheckout', () => {
},
],
router: {
isPassport: false,
availableRoutingOptions: {
onRamp: undefined,
swap: undefined,
Expand Down Expand Up @@ -564,9 +563,6 @@ describe('smartCheckout', () => {
getSigner: jest.fn().mockReturnValue({
getAddress: jest.fn().mockResolvedValue('0xADDRESS'),
}),
provider: {
isPassport: true,
},
} as unknown as Web3Provider;

const result = await smartCheckout(
Expand Down Expand Up @@ -657,7 +653,6 @@ describe('smartCheckout', () => {
},
],
router: {
isPassport: true,
availableRoutingOptions: {
onRamp: undefined,
swap: undefined,
Expand Down
2 changes: 0 additions & 2 deletions packages/checkout/sdk/src/smartCheckout/smartCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ export const smartCheckout = async (
availableRoutingOptions,
);

const isPassport = (provider.provider as any)?.isPassport || false;
return {
sufficient,
transactionRequirements,
router: {
isPassport,
availableRoutingOptions,
routingOutcome,
},
Expand Down

0 comments on commit 238134e

Please sign in to comment.