-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add funds(wip_ * add funds * add transak flow * build fix * more documentation * docs cleanup
- Loading branch information
Showing
11 changed files
with
243 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Hex } from 'viem' | ||
|
||
import { createGenericContext } from './genericContext' | ||
|
||
export interface AddFundsSettings { | ||
walletAddress: string | Hex, | ||
fiatCurrency?: string, | ||
defaultFiatAmount?: string, | ||
defaultCryptoCurrency?: string, | ||
networks?: string | ||
} | ||
|
||
type AddFundsModalContext = { | ||
triggerAddFunds: (settings: AddFundsSettings) => void | ||
closeAddFunds: () => void | ||
addFundsSettings?: AddFundsSettings | ||
} | ||
|
||
export const [useAddFundsModalContext, AddFundsContextProvider] = createGenericContext<AddFundsModalContext>() |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './AddFundsModal' | ||
export * from './CheckoutModal' | ||
export * from './Navigation' |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './useAddFundsModal' | ||
export * from './useCheckoutModal' | ||
export * from './useNavigation' | ||
export * from './useModalTheme' |
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,7 @@ | ||
import { useAddFundsModalContext } from '../contexts/AddFundsModal' | ||
|
||
export const useAddFundsModal = () => { | ||
const { triggerAddFunds, closeAddFunds, addFundsSettings } = useAddFundsModalContext() | ||
|
||
return { triggerAddFunds, closeAddFunds, addFundsSettings } | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { AddFundsSettings } from "../contexts" | ||
|
||
export const TRANSAK_API_KEY = '5911d9ec-46b5-48fa-a755-d59a715ff0cf' | ||
|
||
export const getTransakLink = (addFundsSettings: AddFundsSettings) => { | ||
const defaultNetworks = "ethereum,mainnet,arbitrum,optimism,polygon,polygonzkevm,zksync,base,bnb,oasys,astar,avaxcchain" | ||
|
||
interface Options { | ||
[index: string]: string | undefined | ||
} | ||
|
||
const options: Options = { | ||
apiKey: TRANSAK_API_KEY, | ||
referrerDomain: window.location.origin, | ||
walletAddress: addFundsSettings.walletAddress, | ||
fiatCurrency: addFundsSettings?.fiatCurrency, | ||
disableWalletAddressForm: 'true', | ||
defaultFiatAmount: addFundsSettings?.defaultFiatAmount || '50', | ||
defaultCryptoCurrency: addFundsSettings?.defaultCryptoCurrency || 'USDC', | ||
networks: addFundsSettings?.networks || defaultNetworks | ||
} | ||
|
||
const url = new URL('https://global.transak.com') | ||
Object.keys(options).forEach(k => { | ||
const option = options[k] | ||
if (option) { | ||
url.searchParams.append(k, option) | ||
} | ||
}) | ||
|
||
return url.href | ||
} | ||
|
||
export const fetchTransakSupportedCountries = async () => { | ||
const res = await fetch('https://api.transak.com/api/v2/countries') | ||
const data = await res.json() | ||
|
||
// @ts-ignore-next-line | ||
return data.response.filter(x => x.isAllowed).map(x => x.alpha2) | ||
} |
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,23 @@ | ||
import React from 'react' | ||
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" paddingX="4" paddingBottom="4" height="full" style={{ height: '600px' }}> | ||
<Box as="iframe" width="full" height="full" borderWidth="none" src={link} /> | ||
</Box> | ||
) | ||
} |
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