-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NO CHANGELOG][Checkout Widget] Validate checkout widget inputs (#2209)
- Loading branch information
Showing
6 changed files
with
275 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/checkout/widgets-lib/src/widgets/checkout/functions/deduplicateSaleItemsArray.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { SaleItem } from '@imtbl/checkout-sdk'; | ||
|
||
export function deduplicateSaleItemsArray(items: SaleItem[] | undefined): SaleItem[] { | ||
if (!items || !Array.isArray(items)) return []; | ||
|
||
const uniqueItems = items.reduce((acc, item) => { | ||
const itemIndex = acc.findIndex( | ||
({ productId }) => productId === item.productId, | ||
); | ||
|
||
if (itemIndex !== -1) { | ||
acc[itemIndex] = { ...item, qty: acc[itemIndex].qty + item.qty }; | ||
return acc; | ||
} | ||
|
||
return [...acc, { ...item }]; | ||
}, [] as SaleItem[]); | ||
|
||
return uniqueItems; | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/checkout/widgets-lib/src/widgets/checkout/functions/isValidCheckoutFlow.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { CheckoutFlowType } from '@imtbl/checkout-sdk'; | ||
|
||
/** Orchestration Events List */ | ||
export const checkoutFlows = [ | ||
CheckoutFlowType.CONNECT, | ||
CheckoutFlowType.WALLET, | ||
CheckoutFlowType.SALE, | ||
CheckoutFlowType.SWAP, | ||
CheckoutFlowType.BRIDGE, | ||
CheckoutFlowType.ONRAMP, | ||
CheckoutFlowType.ADD_FUNDS, | ||
]; | ||
|
||
/** | ||
* Check if event is orchestration event | ||
*/ | ||
export function isValidCheckoutFlow(flow: string): boolean { | ||
return checkoutFlows.includes(flow as CheckoutFlowType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters