Skip to content

Commit 86c4869

Browse files
authored
Show more info with needed and reserved funds (#265)
1 parent 97c2332 commit 86c4869

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

packages/ui/src/components/modals/Send.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { useCheckBalance } from '../../hooks/useCheckBalance'
2020
import { useGetSubscanLinks } from '../../hooks/useSubscanLink'
2121
import FromCallData from '../EasySetup/FromCallData'
2222
import { ModalCloseButton } from '../library/ModalCloseButton'
23+
import { formatBnBalance } from '../../utils/formatBnBalance'
2324

2425
const SEND_TOKEN_MENU = 'Send tokens'
2526
const FROM_CALL_DATA_MENU = 'From call data'
@@ -34,11 +35,11 @@ interface Props {
3435

3536
const Send = ({ onClose, className, onSuccess, onFinalized }: Props) => {
3637
const { getSubscanExtrinsicLink } = useGetSubscanLinks()
37-
const { api, isApiReady } = useApi()
38+
const { api, isApiReady, chainInfo } = useApi()
3839
const [isSubmitting, setIsSubmitting] = useState(false)
3940
const { selectedMultiProxy, getMultisigAsAccountBaseInfo, getMultisigByAddress } = useMultiProxy()
4041
const { selectedAccount, selectedSigner } = useAccounts()
41-
const [easyOptionErrorMessage, setEasyOptionErrorMessageorMessage] = useState('')
42+
const [easyOptionErrorMessage, setEasyOptionErrorMessage] = useState('')
4243
const [errorMessage, setErrorMessage] = useState('')
4344
const { addToast } = useToasts()
4445
const possibleOrigin = useMemo(() => {
@@ -123,7 +124,7 @@ const Send = ({ onClose, className, onSuccess, onFinalized }: Props) => {
123124
threshold
124125
])
125126

126-
const { multisigProposalNeededFunds } = useMultisigProposalNeededFunds({
127+
const { multisigProposalNeededFunds, reserved } = useMultisigProposalNeededFunds({
127128
threshold,
128129
signatories: selectedMultisig?.signatories,
129130
call: multisigTx
@@ -135,11 +136,20 @@ const Send = ({ onClose, className, onSuccess, onFinalized }: Props) => {
135136

136137
useEffect(() => {
137138
if (!multisigProposalNeededFunds.isZero() && !hasSignerEnoughFunds) {
139+
const requiredBalanceString = formatBnBalance(
140+
multisigProposalNeededFunds,
141+
chainInfo?.tokenDecimals,
142+
{ tokenSymbol: chainInfo?.tokenSymbol }
143+
)
144+
145+
const reservedString = formatBnBalance(reserved, chainInfo?.tokenDecimals, {
146+
tokenSymbol: chainInfo?.tokenSymbol
147+
})
138148
setErrorMessage(
139-
`The "Signing with" account doesn't have enough funds to submit this transaction`
149+
`The "Signing with" account doesn't have the required ${requiredBalanceString} to submit this transaction. Note that it includes ${reservedString} that will be reserved and returned upon tx approval/cancellation`
140150
)
141151
}
142-
}, [hasSignerEnoughFunds, multisigProposalNeededFunds])
152+
}, [chainInfo, reserved, hasSignerEnoughFunds, multisigProposalNeededFunds])
143153

144154
const onSubmitting = useCallback(() => {
145155
setIsSubmitting(false)
@@ -163,20 +173,20 @@ const Send = ({ onClose, className, onSuccess, onFinalized }: Props) => {
163173
<BalancesTransfer
164174
from={selectedOrigin.address}
165175
onSetExtrinsic={setExtrinsicToCall}
166-
onSetErrorMessage={setEasyOptionErrorMessageorMessage}
176+
onSetErrorMessage={setEasyOptionErrorMessage}
167177
/>
168178
),
169179
[MANUEL_EXTRINSIC_MENU]: (
170180
<ManualExtrinsic
171181
onSetExtrinsic={setExtrinsicToCall}
172-
onSetErrorMessage={setEasyOptionErrorMessageorMessage}
182+
onSetErrorMessage={setEasyOptionErrorMessage}
173183
onSelectFromCallData={() => setSelectedEasyOption(FROM_CALL_DATA_MENU)}
174184
/>
175185
),
176186
[FROM_CALL_DATA_MENU]: (
177187
<FromCallData
178188
onSetExtrinsic={setExtrinsicToCall}
179-
onSetErrorMessage={setEasyOptionErrorMessageorMessage}
189+
onSetErrorMessage={setEasyOptionErrorMessage}
180190
isProxySelected={!!isProxySelected}
181191
/>
182192
)
@@ -257,6 +267,8 @@ const Send = ({ onClose, className, onSuccess, onFinalized }: Props) => {
257267
])
258268

259269
const onChangeEasySetupOption = useCallback((event: SelectChangeEvent<string>) => {
270+
setErrorMessage('')
271+
setEasyOptionErrorMessage('')
260272
setSelectedEasyOption(event.target.value)
261273
}, [])
262274

packages/ui/src/hooks/useMultisigProposalNeededFunds.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface Props {
1313
export const useMultisigProposalNeededFunds = ({ threshold, signatories, call }: Props) => {
1414
const { isApiReady, api, chainInfo } = useApi()
1515
const [min, setMin] = useState(new BN(0))
16+
const [reserved, setReserved] = useState(new BN(0))
1617

1718
useEffect(() => {
1819
if (!isApiReady || !api || !signatories || signatories.length < 2) return
@@ -34,12 +35,13 @@ export const useMultisigProposalNeededFunds = ({ threshold, signatories, call }:
3435
.paymentInfo('5CXQZrh1MSgnGGCdJu3tqvRfCv7t5iQXGGV9UKotrbfhkavs')
3536
.then((info) => {
3637
// add the funds reserved for a multisig call
37-
const reserved = (api.consts.multisig.depositFactor as unknown as BN)
38+
const reservedTemp = (api.consts.multisig.depositFactor as unknown as BN)
3839
.muln(threshold)
3940
.add(api.consts.multisig.depositBase as unknown as BN)
4041

41-
// console.log('reserved', formatBnBalance(reserved, chainInfo.tokenDecimals, { tokenSymbol: chainInfo?.tokenSymbol, numberAfterComma: 3 }))
42-
setMin(reserved.add(info.partialFee))
42+
// console.log('reservedTemp', formatBnBalance(reservedTemp, chainInfo.tokenDecimals, { tokenSymbol: chainInfo?.tokenSymbol, numberAfterComma: 3 }))
43+
setMin(reservedTemp.add(info.partialFee))
44+
setReserved(reservedTemp)
4345
})
4446
.catch(console.error)
4547
} catch (e) {
@@ -48,5 +50,5 @@ export const useMultisigProposalNeededFunds = ({ threshold, signatories, call }:
4850
}
4951
}, [api, call, chainInfo, isApiReady, signatories, threshold])
5052

51-
return { multisigProposalNeededFunds: min }
53+
return { multisigProposalNeededFunds: min, reserved }
5254
}

0 commit comments

Comments
 (0)