Skip to content

Commit 41e6e8e

Browse files
committed
added receive view network swapping
1 parent ea165ff commit 41e6e8e

File tree

8 files changed

+95
-23
lines changed

8 files changed

+95
-23
lines changed

packages/wallet-widget/src/views/FilterMenu.tsx renamed to packages/wallet-widget/src/components/FilterMenu.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ import { ChainId } from '@0xsequence/network'
66
import { useObservable } from 'micro-observables'
77
import { useState } from 'react'
88

9-
import { GradientAvatarList } from '../components/GradientAvatarList'
10-
import { ListCardNav } from '../components/ListCard'
11-
import { ListCardSelect } from '../components/ListCard/ListCardSelect'
12-
import { SlideupDrawer } from '../components/SlideupDrawer'
13-
import { WalletAccountGradient } from '../components/WalletAccountGradient'
149
import { useSettings } from '../hooks'
1510
import { useFiatWalletsMap } from '../hooks/useFiatWalletsMap'
1611
import { getConnectorLogo } from '../utils/wallets'
1712

13+
import { GradientAvatarList } from './GradientAvatarList'
14+
import { ListCardNav } from './ListCard'
15+
import { ListCardSelect } from './ListCard/ListCardSelect'
16+
import { SlideupDrawer } from './SlideupDrawer'
17+
import { WalletAccountGradient } from './WalletAccountGradient'
18+
1819
enum FilterType {
1920
menu = 'Filters',
20-
wallets = 'Select a Wallet',
21-
networks = 'Select a Network',
22-
collections = 'Select a Collection'
21+
wallets = 'Select active Wallets',
22+
networks = 'Select active Networks',
23+
collections = 'Select active Collections'
2324
}
2425

2526
export const FilterMenu = ({
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { Button, Card, ChevronDownIcon, NetworkImage, Text } from '@0xsequence/design-system'
2+
import * as PopoverPrimitive from '@radix-ui/react-popover'
3+
import { useState } from 'react'
4+
import { useChainId, useChains, useSwitchChain } from 'wagmi'
5+
6+
import { WALLET_HEIGHT } from './SequenceWalletProvider'
7+
8+
export const NetworkSelect = () => {
9+
const chains = useChains()
10+
const chainId = useChainId()
11+
const { switchChain } = useSwitchChain()
12+
const [isOpen, toggleOpen] = useState(false)
13+
14+
return (
15+
<PopoverPrimitive.Root open={isOpen} onOpenChange={toggleOpen}>
16+
<PopoverPrimitive.Trigger asChild>
17+
<div
18+
className="flex border-1 border-solid rounded-xl px-4 py-3 cursor-pointer gap-2 items-center select-none"
19+
style={{ height: 52 }}
20+
>
21+
<div className="flex items-center gap-2">
22+
<NetworkImage chainId={chainId} size="sm" />
23+
<Text variant="normal" fontWeight="bold" color="primary">
24+
{chains.find(chain => chain.id === chainId)?.name || chainId}
25+
</Text>
26+
</div>
27+
28+
<div className="text-muted">
29+
<ChevronDownIcon />
30+
</div>
31+
</div>
32+
</PopoverPrimitive.Trigger>
33+
{isOpen && (
34+
<PopoverPrimitive.Content side="bottom" sideOffset={8} align="center" asChild>
35+
<Card className="bg-background-raised backdrop-blur-md relative px-1 py-3" style={{ overflowY: 'hidden' }}>
36+
<div className="flex flex-col gap-2 px-2 overflow-y-auto" style={{ maxHeight: `calc(${WALLET_HEIGHT} / 2)` }}>
37+
{chains.map(chain => (
38+
<div style={{ height: 44 }}>
39+
<Button
40+
className="w-full"
41+
key={chain.id}
42+
shape="square"
43+
onClick={() => {
44+
console.log('chain', chain)
45+
switchChain({ chainId: chain.id })
46+
toggleOpen(false)
47+
}}
48+
leftIcon={() => <NetworkImage chainId={chain.id} size="sm" />}
49+
label={
50+
<div className="flex items-center gap-2">
51+
<Text variant="normal" fontWeight="bold" color="primary">
52+
{chain.name}
53+
</Text>
54+
</div>
55+
}
56+
/>
57+
</div>
58+
))}
59+
</div>
60+
</Card>
61+
</PopoverPrimitive.Content>
62+
)}
63+
</PopoverPrimitive.Root>
64+
)
65+
}

packages/wallet-widget/src/components/SearchLists/CollectiblesList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AnimatePresence } from 'motion/react'
55
import { useState, useMemo } from 'react'
66

77
import { TokenBalanceWithPrice, useGetMoreBalances } from '../../utils'
8-
import { FilterMenu } from '../../views/FilterMenu'
8+
import { FilterMenu } from '../FilterMenu'
99

1010
import { CollectiblesTab } from './CollectiblesList/CollectiblesTab'
1111

packages/wallet-widget/src/components/SearchLists/TokenList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useConfig } from 'wagmi'
1111
import { useSettings } from '../../hooks'
1212
import { computeBalanceFiat, TokenBalanceWithPrice } from '../../utils'
1313
import { useGetMoreBalances } from '../../utils'
14-
import { FilterMenu } from '../../views/FilterMenu'
14+
import { FilterMenu } from '../FilterMenu'
1515

1616
import { CoinsTab } from './TokenList/CoinsTab'
1717

packages/wallet-widget/src/components/SequenceWalletProvider/SequenceWalletProvider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { History, Navigation, NavigationContextProvider, WalletModalContextProvi
1212
import { FiatWalletsMapProvider } from './ProviderComponents/FiatWalletsMapProvider'
1313
import { getHeader, getContent } from './utils'
1414

15-
export const WALLET_WIDTH = 460
15+
export const WALLET_WIDTH = '460px'
16+
export const WALLET_HEIGHT = 'min(800px, 90vh)'
1617

1718
export type SequenceWalletProviderProps = {
1819
children: React.ReactNode

packages/wallet-widget/src/views/History.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import { useMemo, useState } from 'react'
88
import { zeroAddress } from 'viem'
99
import { useConfig } from 'wagmi'
1010

11+
import { FilterMenu } from '../components/FilterMenu'
1112
import { TransactionHistoryList } from '../components/TransactionHistoryList'
1213
import { useSettings } from '../hooks'
1314

14-
import { FilterMenu } from './FilterMenu'
15-
1615
export const History = () => {
1716
const { chains } = useConfig()
1817
const { selectedNetworks, selectedWallets } = useSettings()

packages/wallet-widget/src/views/Home/IntegratedWallet/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { AnimatePresence } from 'motion/react'
1919
import { useMemo, useState } from 'react'
2020
import { useAccount, useConfig } from 'wagmi'
2121

22+
import { FilterMenu } from '../../../components/FilterMenu'
2223
import { StackedIconTag } from '../../../components/IconWrappers/StackedIconTag'
2324
import { ListCardNav } from '../../../components/ListCard/ListCardNav'
2425
import { ListCardNavTable } from '../../../components/ListCardTable/ListCardNavTable'
@@ -29,7 +30,6 @@ import { useNavigation, useSettings } from '../../../hooks'
2930
import { useFiatWalletsMap } from '../../../hooks/useFiatWalletsMap'
3031
import { computeBalanceFiat } from '../../../utils'
3132
import { getConnectorLogo } from '../../../utils/wallets'
32-
import { FilterMenu } from '../../FilterMenu'
3333

3434
import { OperationButtonTemplate } from './Buttons/OperationButtonTemplate'
3535

packages/wallet-widget/src/views/Receive.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
import { getNativeTokenInfoByChainId } from '@0xsequence/connect'
2-
import { Button, Text, CopyIcon, ShareIcon, Image } from '@0xsequence/design-system'
1+
import { getNetwork } from '@0xsequence/connect'
2+
import { Button, Text, CopyIcon, ShareIcon, Image, Card } from '@0xsequence/design-system'
33
import { QRCodeCanvas } from 'qrcode.react'
4-
import React, { useState, useEffect } from 'react'
4+
import { useState, useEffect } from 'react'
55
import { CopyToClipboard } from 'react-copy-to-clipboard'
6-
import { useAccount, useConfig } from 'wagmi'
6+
import { useAccount } from 'wagmi'
77

8+
import { NetworkSelect } from '../components/NetworkSelect'
89
import { HEADER_HEIGHT } from '../constants'
910

11+
const isVowel = (char: string) => ['a', 'e', 'i', 'o', 'u'].includes(char.toLowerCase())
12+
1013
export const Receive = () => {
1114
const { address, chain } = useAccount()
12-
const { chains } = useConfig()
1315
const [isCopied, setCopied] = useState<boolean>(false)
1416

15-
const nativeTokenInfo = getNativeTokenInfoByChainId(chain?.id || 1, chains)
17+
const networkInfo = getNetwork(chain?.id || 1)
18+
const networkName = networkInfo.title || networkInfo.name
1619

1720
useEffect(() => {
1821
if (isCopied) {
@@ -34,7 +37,10 @@ export const Receive = () => {
3437

3538
return (
3639
<div style={{ paddingTop: HEADER_HEIGHT }}>
37-
<div className="flex p-5 pt-3 flex-col justify-center items-center gap-4">
40+
<div className="flex flex-col justify-center items-center p-4 gap-4">
41+
<Card className="p-0 w-fit">
42+
<NetworkSelect />
43+
</Card>
3844
<div className="flex mt-1 w-fit bg-white rounded-xl items-center justify-center p-4">
3945
<QRCodeCanvas value={address || ''} size={200} bgColor="white" fgColor="black" data-id="receiveQR" />
4046
</div>
@@ -43,7 +49,7 @@ export const Receive = () => {
4349
<Text className="text-center leading-[inherit]" variant="medium" color="primary" style={{ fontWeight: '700' }}>
4450
My Wallet
4551
</Text>
46-
<Image className="w-5" src={nativeTokenInfo.logoURI} alt="icon" />
52+
<Image className="w-5 rounded-xs" src={networkInfo.logoURI} alt="icon" />
4753
</div>
4854
<div className="mt-2" style={{ maxWidth: '180px', textAlign: 'center' }}>
4955
<Text
@@ -74,7 +80,7 @@ export const Receive = () => {
7480
overflowWrap: 'anywhere'
7581
}}
7682
>
77-
{`This is a ${nativeTokenInfo.name} address. Please only send assets on the ${nativeTokenInfo.name} network.`}
83+
{`This is a${isVowel(networkName[0]) ? 'n' : ''} ${networkName} address. Please only send assets on the ${networkName} network.`}
7884
</Text>
7985
</div>
8086
</div>

0 commit comments

Comments
 (0)