1
1
import { useAccount , useChains , useDeposit , useWithdraw } from '@orderly.network/hooks' ;
2
- import { API , ChainNamespace } from '@orderly.network/types' ;
2
+ import { ChainNamespace } from '@orderly.network/types' ;
3
3
import { Cross1Icon } from '@radix-ui/react-icons' ;
4
4
import { Button , Dialog , Tabs } from '@radix-ui/themes' ;
5
- import { useNotifications , useSetChain } from '@web3-onboard/react' ;
5
+ import { useNotifications } from '@web3-onboard/react' ;
6
6
import { FixedNumber } from 'ethers' ;
7
7
import { FC , useEffect , useMemo , useState } from 'react' ;
8
8
import { match } from 'ts-pattern' ;
9
9
10
10
import { PendingButton , TokenInput } from '~/components' ;
11
11
import { useIsTestnet } from '~/hooks' ;
12
- import { supportedEvmChainIds , supportedSolanaChainIds } from '~/utils' ;
13
12
14
13
export const OrderlyDeposit : FC < {
15
14
walletBalance : FixedNumber ;
@@ -27,30 +26,22 @@ export const OrderlyDeposit: FC<{
27
26
28
27
const [ isTestnet ] = useIsTestnet ( ) ;
29
28
const { account, state } = useAccount ( ) ;
30
- const [ chains ] = useChains ( isTestnet ? 'testnet' : 'mainnet' , {
31
- filter : ( item : API . Chain ) =>
32
- supportedEvmChainIds . includes ( item . network_infos ?. chain_id ) ||
33
- supportedSolanaChainIds . includes ( item . network_infos ?. chain_id )
34
- } ) ;
35
- const [ { connectedChain : connectedEvmChain } ] = useSetChain ( ) ;
36
- const token = useMemo ( ( ) => {
37
- return Array . isArray ( chains )
38
- ? chains
39
- . find ( ( chain ) => chain . network_infos . chain_id === Number ( connectedEvmChain ?. id ) )
40
- ?. token_infos . find ( ( t ) => t . symbol === 'USDC' )
41
- : undefined ;
42
- } , [ chains , connectedEvmChain ] ) ;
43
- const deposit = useDeposit ( {
29
+ const [ chains ] = useChains ( isTestnet ? 'testnet' : 'mainnet' ) ;
30
+ const token = useMemo (
31
+ ( ) => chains . find ( ( item ) => item . network_infos . chain_id === account . chainId ) ?. token_infos [ 0 ] ,
32
+ [ chains , account . chainId ]
33
+ ) ;
34
+ const { deposit, approve, allowance, setQuantity } = useDeposit ( {
44
35
address : token ?. address ,
45
36
decimals : token ?. decimals ,
46
37
srcToken : token ?. symbol ,
47
- srcChainId : Number ( connectedEvmChain ?. id )
38
+ srcChainId : Number ( account . chainId )
48
39
} ) ;
49
40
50
41
useEffect ( ( ) => {
51
42
if ( amount == null ) return ;
52
- deposit . setQuantity ( amount . toString ( ) ) ;
53
- } , [ amount , deposit ] ) ;
43
+ setQuantity ( amount . toString ( ) ) ;
44
+ } , [ amount , setQuantity ] ) ;
54
45
useEffect ( ( ) => {
55
46
if ( ! newOrderlyBalance || ! newWalletBalance ) {
56
47
setDisabled ( true ) ;
@@ -130,14 +121,14 @@ export const OrderlyDeposit: FC<{
130
121
if ( amount == null ) return ;
131
122
132
123
if ( isDeposit ) {
133
- if ( Number ( deposit . allowance ) < amount . toUnsafeFloat ( ) ) {
124
+ if ( Number ( allowance ) < amount . toUnsafeFloat ( ) ) {
134
125
const { update } = customNotification ( {
135
126
eventCode : 'approval' ,
136
127
type : 'pending' ,
137
128
message : 'Approving USDC for deposit...'
138
129
} ) ;
139
130
try {
140
- await deposit . approve ( amount . toString ( ) ) ;
131
+ await approve ( amount . toString ( ) ) ;
141
132
update ( {
142
133
eventCode : 'approvalSuccess' ,
143
134
type : 'success' ,
@@ -161,7 +152,7 @@ export const OrderlyDeposit: FC<{
161
152
message : 'Depositing USDC into your Orderly Account...'
162
153
} ) ;
163
154
try {
164
- await deposit . deposit ( ) ;
155
+ await deposit ( ) ;
165
156
update ( {
166
157
eventCode : 'depositSuccess' ,
167
158
type : 'success' ,
@@ -218,7 +209,7 @@ export const OrderlyDeposit: FC<{
218
209
} }
219
210
>
220
211
{ isDeposit
221
- ? amount != null && Number ( deposit . allowance ) < amount . toUnsafeFloat ( )
212
+ ? amount != null && Number ( allowance ) < amount . toUnsafeFloat ( )
222
213
? 'Approve'
223
214
: 'Deposit'
224
215
: 'Withdraw' }
@@ -305,7 +296,7 @@ export const OrderlyDeposit: FC<{
305
296
}
306
297
} }
307
298
>
308
- Mint 1k USDC via faucet
299
+ Request USDC via faucet
309
300
</ PendingButton >
310
301
) }
311
302
</ div >
0 commit comments