1
- import { useEffect , useState } from 'react' ;
2
- import { rpcNodeAtom } from 'store/app' ;
3
1
import { useAtomValue } from 'jotai' ;
2
+ import { useEffect , useState } from 'react' ;
4
3
import { querySwingsetParams } from 'utils/swingsetParams' ;
4
+ import { displayFunctionsAtom , pursesAtom , rpcNodeAtom } from 'store/app' ;
5
5
import ActionsDialog from './ActionsDialog' ;
6
-
7
- // Increment every time the current terms change.
8
- export const currentTermsIndex = 1 ;
6
+ import LeapLiquidityModal , { Direction } from './LiquidityModal' ;
9
7
10
8
const useSmartWalletFeeQuery = ( rpc ?: string ) => {
11
- const [ smartWalletFee , setFee ] = useState < bigint | null > ( null ) ;
9
+ const [ smartWalletFee , setFee ] = useState < {
10
+ fee : bigint ;
11
+ feeUnit : bigint ;
12
+ } | null > ( null ) ;
12
13
const [ error , setError ] = useState < Error | null > ( null ) ;
13
14
14
15
useEffect ( ( ) => {
@@ -23,7 +24,8 @@ const useSmartWalletFeeQuery = (rpc?: string) => {
23
24
const feeUnit = params . params . beansPerUnit . find (
24
25
( { key } : { key : string } ) => key === 'feeUnit'
25
26
) ?. beans ;
26
- setFee ( BigInt ( beansPerSmartWallet ) / BigInt ( feeUnit ) ) ;
27
+ assert ( feeUnit ) ;
28
+ setFee ( { fee : BigInt ( beansPerSmartWallet ) , feeUnit : BigInt ( feeUnit ) } ) ;
27
29
} catch ( e ) {
28
30
setError ( e as Error ) ;
29
31
}
@@ -36,30 +38,72 @@ const useSmartWalletFeeQuery = (rpc?: string) => {
36
38
37
39
return { smartWalletFee, error } ;
38
40
} ;
41
+
39
42
type Props = {
40
43
onConfirm : ( ) => void ;
41
44
isOpen : boolean ;
42
45
onClose : ( ) => void ;
43
46
} ;
44
47
45
- const ProvisionSmartWalletDialog = ( { onConfirm, isOpen, onClose } : Props ) => {
48
+ const ProvisionSmartWalletNoticeDialog = ( {
49
+ onConfirm,
50
+ isOpen,
51
+ onClose,
52
+ } : Props ) => {
46
53
const rpc = useAtomValue ( rpcNodeAtom ) ;
47
54
const { smartWalletFee, error : _smartWalletFeeError } =
48
55
useSmartWalletFeeQuery ( rpc ) ;
49
56
50
57
const smartWalletFeeForDisplay = smartWalletFee
51
- ? smartWalletFee + ' IST'
58
+ ? String ( smartWalletFee . fee / smartWalletFee . feeUnit ) + ' IST'
52
59
: null ;
53
60
61
+ const purses = useAtomValue ( pursesAtom ) ;
62
+ const istPurse = purses ?. find ( p => p . brandPetname === 'IST' ) ;
63
+ const { displayAmount, getDecimalPlaces } =
64
+ useAtomValue ( displayFunctionsAtom ) ?? { } ;
65
+
54
66
const body = (
55
- < span >
56
- To interact with contracts on the Agoric chain, a smart wallet must be
57
- created for your account. As an anti-spam measure, you will need{ ' ' }
58
- { smartWalletFeeForDisplay && < b > { smartWalletFeeForDisplay } </ b > } to fund
59
- its provision which will be deposited into the reserve pool. Click
60
- "Proceed" to provision wallet and submit transaction.
61
- </ span >
67
+ < >
68
+ < div >
69
+ To interact with contracts on the Agoric chain, a smart wallet must be
70
+ created for your account. You will need{ ' ' }
71
+ { smartWalletFeeForDisplay && < b > { smartWalletFeeForDisplay } </ b > } to fund
72
+ its provision which will be deposited into the reserve pool. Click
73
+ "Proceed" to provision wallet and submit transaction.
74
+ </ div >
75
+ < div className = "my-4 flex justify-center gap-4" >
76
+ { istPurse && displayAmount && (
77
+ < div className = "flex items-center" >
78
+ < span >
79
+ IST Balance: < b > { displayAmount ( istPurse . currentAmount ) } </ b >
80
+ </ span >
81
+ </ div >
82
+ ) }
83
+ { istPurse && (
84
+ < LeapLiquidityModal
85
+ selectedAsset = { istPurse . brand }
86
+ direction = { Direction . deposit }
87
+ />
88
+ ) }
89
+ </ div >
90
+ </ >
62
91
) ;
92
+ const istDecimals =
93
+ istPurse && getDecimalPlaces && getDecimalPlaces ( istPurse . brand ) ;
94
+
95
+ // "feeUnit" is observed to be 1000000000000n, so when "fee" is 1000000000000n
96
+ // that means 1 IST (after dividing "fee" by "feeUnit"). To convert to uIST,
97
+ // we then multiply by 10^6.
98
+ const denominatedSmartWalletFee =
99
+ istDecimals &&
100
+ smartWalletFee &&
101
+ ( smartWalletFee . fee / smartWalletFee . feeUnit ) * 10n ** BigInt ( istDecimals ) ;
102
+
103
+ const hasRequiredFee =
104
+ denominatedSmartWalletFee &&
105
+ istPurse !== undefined &&
106
+ istPurse . currentAmount . value >= denominatedSmartWalletFee ;
63
107
64
108
return (
65
109
< ActionsDialog
@@ -73,8 +117,9 @@ const ProvisionSmartWalletDialog = ({ onConfirm, isOpen, onClose }: Props) => {
73
117
} }
74
118
onClose = { onClose }
75
119
initialFocusPrimary = { true }
120
+ primaryActionDisabled = { ! hasRequiredFee }
76
121
/>
77
122
) ;
78
123
} ;
79
124
80
- export default ProvisionSmartWalletDialog ;
125
+ export default ProvisionSmartWalletNoticeDialog ;
0 commit comments