Skip to content

Commit

Permalink
add funds
Browse files Browse the repository at this point in the history
  • Loading branch information
SamueleA committed May 23, 2024
1 parent 242771b commit 97eab28
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 64 deletions.
19 changes: 19 additions & 0 deletions packages/checkout/src/contexts/AddFundsModal.ts
Original file line number Diff line number Diff line change
@@ -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<AddFundsModalContext>()
11 changes: 0 additions & 11 deletions packages/checkout/src/contexts/CheckoutModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions packages/checkout/src/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './AddFundsModal'
export * from './CheckoutModal'
export * from './Navigation'
1 change: 1 addition & 0 deletions packages/checkout/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './useAddFundsModal'
export * from './useCheckoutModal'
export * from './useNavigation'
export * from './useModalTheme'
7 changes: 7 additions & 0 deletions packages/checkout/src/hooks/useAddFundsModal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { useAddFundsModalContext } from '../contexts/AddFundsModal'

export const useAddFundsModal = () => {
const { triggerAddFunds, closeAddFunds, addFundsSettings } = useAddFundsModalContext()

return { triggerAddFunds, closeAddFunds, addFundsSettings }
}
112 changes: 59 additions & 53 deletions packages/checkout/src/shared/components/KitCheckoutProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
NavigationContextProvider,
CheckoutModalContextProvider,
CheckoutSettings,
AddFundsContextProvider,
AddFundsSettings
} from '../../contexts'
import { NavigationHeader } from '../../shared/components/NavigationHeader'
Expand Down Expand Up @@ -117,64 +118,69 @@ export const KitCheckoutContent = ({ children }: KitCheckoutProvider) => {
}, [openCheckoutModal, openAddFundsModal])

return (
<CheckoutModalContextProvider
<AddFundsContextProvider
value={{
triggerCheckout,
closeCheckout,
settings,
triggerAddFunds,
closeAddFunds,
addFundsSettings,
theme,
}}
>
<NavigationContextProvider value={{ history, setHistory }}>
<div id="kit-checkout">
<ThemeProvider root="#kit-checkout" scope="kit" theme={theme}>
<AnimatePresence>
{openCheckoutModal && (
<Modal
contentProps={{
style: {
maxWidth: '400px',
height: 'auto',
...getModalPositionCss(position)
}
}}
scroll={false}
backdropColor="backgroundBackdrop"
onClose={() => setOpenCheckoutModal(false)}
>
<Box id="sequence-kit-checkout-content">
{getCheckoutHeader()}
{getCheckoutContent()}
</Box>
</Modal>
)}
{openAddFundsModal && (
<Modal
contentProps={{
style: {
maxWidth: '400px',
height: 'auto',
...getModalPositionCss(position)
}
}}
scroll={false}
backdropColor="backgroundBackdrop"
onClose={() => setOpenCheckoutModal(false)}
>
<Box id="sequence-kit-add-funds-content">
{getAddFundsHeader()}
{getAddFundsContent()}
</Box>
</Modal>
)}
</AnimatePresence>
</ThemeProvider>
</div>
{children}
</NavigationContextProvider>
</CheckoutModalContextProvider>
<CheckoutModalContextProvider
value={{
triggerCheckout,
closeCheckout,
settings,
theme,
}}
>
<NavigationContextProvider value={{ history, setHistory }}>
<div id="kit-checkout">
<ThemeProvider root="#kit-checkout" scope="kit" theme={theme}>
<AnimatePresence>
{openCheckoutModal && (
<Modal
contentProps={{
style: {
maxWidth: '400px',
height: 'auto',
...getModalPositionCss(position)
}
}}
scroll={false}
backdropColor="backgroundBackdrop"
onClose={() => setOpenCheckoutModal(false)}
>
<Box id="sequence-kit-checkout-content">
{getCheckoutHeader()}
{getCheckoutContent()}
</Box>
</Modal>
)}
{openAddFundsModal && (
<Modal
contentProps={{
style: {
maxWidth: '400px',
height: 'auto',
...getModalPositionCss(position)
}
}}
scroll={false}
backdropColor="backgroundBackdrop"
onClose={() => setOpenCheckoutModal(false)}
>
<Box id="sequence-kit-add-funds-content">
{getAddFundsHeader()}
{getAddFundsContent()}
</Box>
</Modal>
)}
</AnimatePresence>
</ThemeProvider>
</div>
{children}
</NavigationContextProvider>
</CheckoutModalContextProvider>
</AddFundsContextProvider>
)
}
22 changes: 22 additions & 0 deletions packages/checkout/src/views/AddFunds.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Box alignItems="center" width="full" height="full" paddingX="4">
<Box as="iframe" width="full" height="full" borderWidth="none" src={link} />
</Box>
)
}
1 change: 1 addition & 0 deletions packages/checkout/src/views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './PendingTransaction'
export * from './TransactionSuccess'
export * from './TransactionError'
export * from './CheckoutSelection'
export * from './AddFunds'

0 comments on commit 97eab28

Please sign in to comment.