@@ -2,19 +2,25 @@ import { BasicModal, Button, Text } from '@interchain-ui/react';
22import { useAgoric } from '../hooks' ;
33import { stringifyValue } from '@agoric/web-components' ;
44import { AssetKind } from '@agoric/ertp' ;
5- import { OnboardIstModal } from './OnboardIstModal ' ;
5+ import { OnboardTokenModal } from './OnboardTokenModal ' ;
66
77const feeDecimals = 6 ;
88
9- const defaultContent = ( fee ?: bigint ) => {
9+ const formatFeeUnit = ( unit ?: string ) => {
10+ if ( ! unit ) return '' ;
11+ return unit === 'ubld' ? 'BLD' : unit === 'uist' ? 'IST' : unit ;
12+ } ;
13+
14+ const defaultContent = ( fee ?: bigint , feeUnit ?: string ) => {
1015 const prettyFee = stringifyValue ( fee , AssetKind . NAT , feeDecimals ) ;
16+ const prettyFeeUnit = formatFeeUnit ( feeUnit ) ;
1117
1218 return (
1319 < Text fontSize = "large" >
1420 To interact with contracts on the Agoric chain, a smart wallet must be
1521 created for your account. You will need{ ' ' }
1622 < Text fontSize = "large" as = "span" fontWeight = "$bold" >
17- { prettyFee } IST
23+ { prettyFee } { prettyFeeUnit }
1824 </ Text > { ' ' }
1925 to fund its provision which will be deposited into the reserve pool. Click
2026 "Proceed" to provision wallet and submit transaction.
@@ -25,19 +31,62 @@ const defaultContent = (fee?: bigint) => {
2531export type Props = {
2632 onClose : ( ) => void ;
2733 proceed ?: ( ) => void ;
28- mainContent ?: ( fee ?: bigint ) => JSX . Element ;
34+ mainContent ?: ( fee ?: bigint , feeUnit ?: string ) => JSX . Element ;
2935} ;
3036
3137export const ProvisionNoticeModal = ( {
3238 onClose,
3339 proceed,
3440 mainContent = defaultContent ,
3541} : Props ) => {
36- const { smartWalletProvisionFee, purses } = useAgoric ( ) ;
42+ const { smartWalletProvisionFee, smartWalletProvisionFeeUnit, purses } =
43+ useAgoric ( ) ;
44+ const bldPurse = purses ?. find ( p => p . brandPetname === 'BLD' ) ;
3745 const istPurse = purses ?. find ( p => p . brandPetname === 'IST' ) ;
3846 const canProceed =
3947 ! smartWalletProvisionFee ||
40- ( istPurse && istPurse . currentAmount . value >= smartWalletProvisionFee ) ;
48+ ( smartWalletProvisionFeeUnit === 'ubld' &&
49+ bldPurse &&
50+ bldPurse . currentAmount . value >= smartWalletProvisionFee ) ||
51+ ( smartWalletProvisionFeeUnit === 'uist' &&
52+ istPurse &&
53+ istPurse . currentAmount . value >= smartWalletProvisionFee ) ;
54+
55+ const renderBalance = ( ) => {
56+ if ( smartWalletProvisionFeeUnit === 'ubld' && bldPurse ) {
57+ return (
58+ < div className = "flex items-center" >
59+ < Text fontSize = "large" >
60+ BLD Balance:{ ' ' }
61+ < Text as = "span" fontSize = "large" fontWeight = "$bold" >
62+ { stringifyValue (
63+ bldPurse . currentAmount . value ,
64+ AssetKind . NAT ,
65+ feeDecimals ,
66+ ) }
67+ </ Text >
68+ </ Text >
69+ </ div >
70+ ) ;
71+ }
72+ if ( smartWalletProvisionFeeUnit === 'uist' && istPurse ) {
73+ return (
74+ < div className = "flex items-center" >
75+ < Text fontSize = "large" >
76+ IST Balance:{ ' ' }
77+ < Text as = "span" fontSize = "large" fontWeight = "$bold" >
78+ { stringifyValue (
79+ istPurse . currentAmount . value ,
80+ AssetKind . NAT ,
81+ feeDecimals ,
82+ ) }
83+ </ Text >
84+ </ Text >
85+ </ div >
86+ ) ;
87+ }
88+ return null ;
89+ } ;
4190
4291 return (
4392 < BasicModal
@@ -48,24 +97,12 @@ export const ProvisionNoticeModal = ({
4897 onClose = { onClose }
4998 >
5099 < div className = "my-4" >
51- { mainContent ( smartWalletProvisionFee ) }
100+ { mainContent ( smartWalletProvisionFee , smartWalletProvisionFeeUnit ) }
52101 < div className = "my-4 flex justify-center gap-4" >
53- { istPurse && (
54- < div className = "flex items-center" >
55- < Text fontSize = "large" >
56- IST Balance:{ ' ' }
57- < Text as = "span" fontSize = "large" fontWeight = "$bold" >
58- { istPurse &&
59- stringifyValue (
60- istPurse . currentAmount . value ,
61- AssetKind . NAT ,
62- feeDecimals ,
63- ) }
64- </ Text >
65- </ Text >
66- </ div >
67- ) }
68- < OnboardIstModal />
102+ { renderBalance ( ) }
103+ < OnboardTokenModal
104+ token = { smartWalletProvisionFeeUnit === 'ubld' ? 'BLD' : 'IST' }
105+ />
69106 </ div >
70107 </ div >
71108 < div className = "flex justify-end gap-2 mt-6" >
0 commit comments