diff --git a/packages/checkout/src/contexts/AddFundsModal.ts b/packages/checkout/src/contexts/AddFundsModal.ts new file mode 100644 index 00000000..29166e0e --- /dev/null +++ b/packages/checkout/src/contexts/AddFundsModal.ts @@ -0,0 +1,19 @@ +import { Theme } from '@0xsequence/kit' + +import { createGenericContext } from './genericContext' + +export interface AddFundsSettings { + walletAddress: string, + fiatCurrency: string, + defaultFiatAmount?: string, + defaultCryptoCurrency?: string, + networks?: string +} + +type AddFundsModalContext = { + triggerAddFunds: (settings: AddFundsSettings) => void + closeAddFunds: () => void + addFundsSettings?: AddFundsSettings +} + +export const [useAddFundsModalContext, AddFundsContextProvider] = createGenericContext() diff --git a/packages/checkout/src/contexts/CheckoutModal.ts b/packages/checkout/src/contexts/CheckoutModal.ts index b1018ac3..c06a9e8e 100644 --- a/packages/checkout/src/contexts/CheckoutModal.ts +++ b/packages/checkout/src/contexts/CheckoutModal.ts @@ -38,21 +38,10 @@ export interface CheckoutSettings { orderSummaryItems: OrderSummaryItem[] } -export interface AddFundsSettings { - walletAddress: string, - fiatCurrency: string, - defaultFiatAmount?: string, - defaultCryptoCurrency?: string, - networks?: string -} - type CheckoutModalContext = { triggerCheckout: (settings: CheckoutSettings) => void closeCheckout: () => void - triggerAddFunds: (settings: AddFundsSettings) => void - closeAddFunds: () => void settings?: CheckoutSettings - addFundsSettings?: AddFundsSettings theme: Theme } diff --git a/packages/checkout/src/contexts/index.ts b/packages/checkout/src/contexts/index.ts index c61c68be..5a647be5 100644 --- a/packages/checkout/src/contexts/index.ts +++ b/packages/checkout/src/contexts/index.ts @@ -1,2 +1,3 @@ +export * from './AddFundsModal' export * from './CheckoutModal' export * from './Navigation' diff --git a/packages/checkout/src/hooks/index.ts b/packages/checkout/src/hooks/index.ts index 9d84b724..fdc3b30d 100644 --- a/packages/checkout/src/hooks/index.ts +++ b/packages/checkout/src/hooks/index.ts @@ -1,3 +1,4 @@ +export * from './useAddFundsModal' export * from './useCheckoutModal' export * from './useNavigation' export * from './useModalTheme' diff --git a/packages/checkout/src/hooks/useAddFundsModal.ts b/packages/checkout/src/hooks/useAddFundsModal.ts new file mode 100644 index 00000000..e6ae9861 --- /dev/null +++ b/packages/checkout/src/hooks/useAddFundsModal.ts @@ -0,0 +1,7 @@ +import { useAddFundsModalContext } from '../contexts/AddFundsModal' + +export const useAddFundsModal = () => { + const { triggerAddFunds, closeAddFunds, addFundsSettings } = useAddFundsModalContext() + + return { triggerAddFunds, closeAddFunds, addFundsSettings } +} diff --git a/packages/checkout/src/shared/components/KitCheckoutProvider.tsx b/packages/checkout/src/shared/components/KitCheckoutProvider.tsx index 17e55f88..a414d412 100644 --- a/packages/checkout/src/shared/components/KitCheckoutProvider.tsx +++ b/packages/checkout/src/shared/components/KitCheckoutProvider.tsx @@ -10,6 +10,7 @@ import { NavigationContextProvider, CheckoutModalContextProvider, CheckoutSettings, + AddFundsContextProvider, AddFundsSettings } from '../../contexts' import { NavigationHeader } from '../../shared/components/NavigationHeader' @@ -117,64 +118,69 @@ export const KitCheckoutContent = ({ children }: KitCheckoutProvider) => { }, [openCheckoutModal, openAddFundsModal]) return ( - - -
- - - {openCheckoutModal && ( - setOpenCheckoutModal(false)} - > - - {getCheckoutHeader()} - {getCheckoutContent()} - - - )} - {openAddFundsModal && ( - setOpenCheckoutModal(false)} - > - - {getAddFundsHeader()} - {getAddFundsContent()} - - - )} - - -
- {children} -
-
+ + +
+ + + {openCheckoutModal && ( + setOpenCheckoutModal(false)} + > + + {getCheckoutHeader()} + {getCheckoutContent()} + + + )} + {openAddFundsModal && ( + setOpenCheckoutModal(false)} + > + + {getAddFundsHeader()} + {getAddFundsContent()} + + + )} + + +
+ {children} +
+
+ ) } diff --git a/packages/checkout/src/views/AddFunds.tsx b/packages/checkout/src/views/AddFunds.tsx new file mode 100644 index 00000000..420189a1 --- /dev/null +++ b/packages/checkout/src/views/AddFunds.tsx @@ -0,0 +1,22 @@ +import { + Box, +} from '@0xsequence/design-system' + +import { useAddFundsModal } from '../hooks' +import { getTransakLink } from '../utils/transak' + +export const AddFundsContent = () => { + const { addFundsSettings } = useAddFundsModal() + + if (!addFundsSettings) { + return + } + + const link = getTransakLink(addFundsSettings) + + return ( + + + + ) +} diff --git a/packages/checkout/src/views/index.ts b/packages/checkout/src/views/index.ts index 5110bd5a..e77ab8c6 100644 --- a/packages/checkout/src/views/index.ts +++ b/packages/checkout/src/views/index.ts @@ -2,3 +2,4 @@ export * from './PendingTransaction' export * from './TransactionSuccess' export * from './TransactionError' export * from './CheckoutSelection' +export * from './AddFunds'