Skip to content

Commit

Permalink
payment options modal UI (#136)
Browse files Browse the repository at this point in the history
* logic for triggering new payment select modal

* payment seleciton(wip)

* added buy with currency flow

* send transactions utility function

* swap and buy

* utility function

* sardine checkout (wip)

* credit card payment

* card height adjustment

* disable other buttons when a TX is in progress

* adde sales contract-specific hook

* renamed tokenId, collectionAddress and price fields

* replaced chainId field with more generic chain field

* clean up helpers

* transfer to wallet

* transfer funds modal context

* export transfer funds modal

* transfer funds modal

* fixed add funds modal, trigger modal

* new pnpm lock file

* return txhash from onsuccess callback

* fix peer deps

* onClose callbacks

* rename erc1155 sales contract setting modal

* callback fns

* disable mock connector

* moved sardine

* refactor selectpaymentmodal settings

* wip

* item description section

* price section

* price formatted

* price section and layout

* added footer

* crypto option (WIP)

* show list of options

* on click purchase logic; fixed flickering issue

* fuzzy search wup

* fuzzy search

* pay with credit card WIP

* sardine logo

* display fiat price

* credit card section

* remove unused settings

* hide sections if only one item

* native token information

* return no quotes in case of error

* fix currency info for native toknes

* logic for native token tranasctions

* disabling swap paymetns with native currency

* fixes
  • Loading branch information
SamueleA authored Sep 25, 2024
1 parent a55a18b commit 0591274
Show file tree
Hide file tree
Showing 25 changed files with 5,055 additions and 5,730 deletions.
15 changes: 10 additions & 5 deletions examples/react/src/components/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ export const Connected = () => {
accountAddress: account
})

console.log('feeOptions', pendingFeeOptionConfirmation.options)
console.log('nativeTokenBalance', nativeTokenBalance)
console.log('tokenBalances', tokenBalances)

const balances = pendingFeeOptionConfirmation.options.map(option => {
if (option.token.contractAddress === null) {
return {
Expand Down Expand Up @@ -251,13 +247,22 @@ export const Connected = () => {
if (!address) {
return
}

// NATIVE token sale
// const currencyAddress = ethers.ZeroAddress
// const salesContractAddress = '0xf0056139095224f4eec53c578ab4de1e227b9597'
// const collectionAddress = '0x92473261f2c26f2264429c451f70b0192f858795'
// const price = '200000000000000'

// // ERC-20 contract
const currencyAddress = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359'
const salesContractAddress = '0xe65b75eb7c58ffc0bf0e671d64d0e1c6cd0d3e5b'
const collectionAddress = '0xdeb398f41ccd290ee5114df7e498cf04fac916cb'
const price = '20000'

const chainId = 137
const tokenId = '1'
const nftQuantity = '1'
const collectionAddress = '0xdeb398f41ccd290ee5114df7e498cf04fac916cb'

openERC1155SaleContractPaymentModal({
chain: chainId,
Expand Down
5 changes: 4 additions & 1 deletion packages/checkout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
"@0xsequence/metadata": "^2.0.6",
"@0xsequence/network": "^2.0.6",
"@tanstack/react-query": "^5.37.1",
"fuse.js": "^6.6.2",
"qrcode.react": "^3.1.0",
"react-copy-to-clipboard": "^5.1.0"
},
"peerDependencies": {
"@0xsequence/design-system": ">= 1.7.6",
"0xsequence": ">= 2.0.1",
"@0xsequence/api": ">= 2.0.1",
"@0xsequence/design-system": ">= 1.7.6",
"@0xsequence/indexer": ">= 2.0.1",
"@0xsequence/metadata": ">= 2.0.1",
"@0xsequence/network": ">= 2.0.1",
Expand All @@ -59,10 +60,12 @@
"@0xsequence/design-system": "^1.7.6",
"@0xsequence/kit": "workspace:*",
"@types/react-copy-to-clipboard": "^5.0.7",
"@vitejs/plugin-react": "^4.3.0",
"ethers": "^6.13.0",
"framer-motion": "^8.5.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"vite": "^5.2.11",
"wagmi": "^2.9.5"
}
}
3 changes: 2 additions & 1 deletion packages/checkout/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const HEADER_HEIGHT = '54px'
export const CARD_HEIGHT = '130px'
export const CARD_HEIGHT_MOBILE = '180px'
export const CARD_HEIGHT_MOBILE = '180px'
export const PAYMENT_SELECTION_MODAL_HEIGHT = '786px'
2 changes: 0 additions & 2 deletions packages/checkout/src/contexts/SelectPaymentModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export interface SelectPaymentSettings {
enableMainCurrencyPayment?: boolean
enableSwapPayments?: boolean
enableCreditCardPayments?: boolean
enableTransferFunds?: boolean
enableFiatOnRamp?: boolean
}

type SelectPaymentModalContext = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
TransferFundsContextProvider,
TransferFundsSettings,
} from '../../contexts'
import { PAYMENT_SELECTION_MODAL_HEIGHT } from '../../constants'
import { NavigationHeader } from '../../shared/components/NavigationHeader'
import {
PendingTransaction,
Expand Down Expand Up @@ -250,7 +251,8 @@ export const KitCheckoutContent = ({ children }: KitCheckoutProvider) => {
<Modal
contentProps={{
style: {
height: 'auto',
maxHeight: PAYMENT_SELECTION_MODAL_HEIGHT,
maxWidth: '420px',
...getModalPositionCss(position)
}
}}
Expand Down
66 changes: 0 additions & 66 deletions packages/checkout/src/views/PaymentSelection/FiatOnRamp.tsx

This file was deleted.

64 changes: 64 additions & 0 deletions packages/checkout/src/views/PaymentSelection/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Box, Text, SequenceIcon } from '@0xsequence/design-system'

export const Footer = () => {
return (
<Box position="fixed" height="7" marginTop="2" width="full" style={{ bottom: '4px' }}>
<Box gap="4" justifyContent="center" alignItems="center">
<Box
as="a"
href="https://sequence.xyz/"
rel="noopener noreferrer"
target="_blank"
textDecoration="none"
opacity={{ hover: '80' }}
gap="1"
justifyContent="center"
alignItems="center"
cursor="pointer"
>
<SequenceIcon color="text50" />
<Text color="text50" variant="xsmall">Sequence</Text>
</Box>
<Box
as="a"
href="https://sequence.xyz/privacy"
rel="noopener noreferrer"
target="_blank"
textDecoration="none"
opacity={{ hover: '80' }}
cursor="pointer"
>
<Text color="text50" variant="xsmall">
Privacy
</Text>
</Box>
<Box
as="a"
href="https://sequence.xyz/terms"
rel="noopener noreferrer"
target="_blank"
textDecoration="none"
opacity={{ hover: '80' }}
cursor="pointer"
>
<Text color="text50" variant="xsmall">
Terms
</Text>
</Box>
<Box
as="a"
href="https://docs.sequence.xyz/"
rel="noopener noreferrer"
target="_blank"
textDecoration="none"
opacity={{ hover: '80' }}
cursor="pointer"
>
<Text color="text50" variant="xsmall">
Help
</Text>
</Box>
</Box>
</Box>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
NetworkBadge,
CollectibleTileImage,
useTokenMetadata
} from '@0xsequence/kit'
import { Box, Spinner, Text } from '@0xsequence/design-system'
import { findSupportedNetwork } from '@0xsequence/network'

import { useSelectPaymentModal } from '../../../hooks'

export const ItemDescription = () => {
const { selectPaymentSettings } = useSelectPaymentModal()
const nftQuantity = selectPaymentSettings!.nftQuantity
const chain = selectPaymentSettings!.chain
const network = findSupportedNetwork(chain)
const chainId = network?.chainId || 137
const collectionAddress = selectPaymentSettings!.collectionAddress
const tokenId = selectPaymentSettings!.tokenId
const { data: tokenMetadatas, isLoading: isLoadingTokenMetadatas } = useTokenMetadata(chainId, collectionAddress, [tokenId])
const tokenMetadata = tokenMetadatas?.[0]

const isLoading = isLoadingTokenMetadatas

if (isLoading) {
<Box marginBottom="2" paddingX="6" gap="3" style={{ height: '72px' }}>
<Spinner />
</Box>
}

return (
<Box marginBottom="2" paddingX="6" gap="5" alignItems="center">
<Box position="relative">
<Box
background="backgroundControl"
borderRadius="md"
style={{
height: "60px",
width: "60px",
transform: "rotate(-15deg)"
}}
/>
<Box
position="absolute"
borderRadius="md"
style={{
height: "60px",
width: "60px",
bottom: '0'
}}
>
<CollectibleTileImage imageUrl={tokenMetadata?.image} />
</Box>
</Box>
<Box flexDirection="column" gap="0.5">
<Text
variant="normal"
color="text100"
fontWeight="bold"
>
{tokenMetadata?.name || "Unknown"}
</Text>
<Text variant="normal" color="text50" fontWeight="medium">
{Number(nftQuantity) === 1 ? `${nftQuantity} item` : `${nftQuantity} items`}
</Text>
<Box marginTop="1">
<NetworkBadge chainId={chainId} />
</Box>
</Box>
</Box>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Box, Card, Text } from '@0xsequence/design-system'

interface PaymentProviderOptionProps {
name: string
onClick: () => void
isSelected: boolean
isRecommended: boolean
logo: JSX.Element
}

export const PaymentProviderOption = ({
name,
onClick,
isSelected,
isRecommended,
logo
}: PaymentProviderOptionProps) => {
return (
<Card
borderColor={isSelected ? 'backgroundRaised' : 'transparent' }
borderWidth="thick"
borderStyle="solid"
justifyContent="space-between"
padding="4"
onClick={onClick}
opacity={{
hover: '80',
base: '100'
}}
cursor="pointer"
>
<Box justifyContent="space-between" width="full">
<Box justifyContent="space-between" alignItems="center" gap="3">
<Box borderRadius="md">
{logo}
</Box>
<Text
variant="normal"
fontWeight="bold"
color="text80"
>
{name}
</Text>
</Box>
<Box flexDirection="row" justifyContent="center" alignItems="center" gap="3">
{isRecommended && (
<Text color="text50" variant="small">Recommended</Text>
)}
</Box>
</Box>
</Card>
)
}
Loading

0 comments on commit 0591274

Please sign in to comment.