Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix: Balance display should not show the token and should not format the amount #462

Merged
merged 16 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/ui/src/components/CallInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Link } from './library'
import { usePjsLinks } from '../hooks/usePjsLinks'
import { Alert } from '@mui/material'
import { ApiPromise } from '@polkadot/api'
import { isTypeBalance, isTypeAccount } from '../utils'
import { isTypeBalanceWithBalanceCall, isTypeAccount } from '../utils'
import { CallDataInfoFromChain } from '../hooks/usePendingTx'

interface Props {
Expand Down Expand Up @@ -128,7 +128,7 @@ const createUlTree = ({ name, args, decimals, unit, api, typeName }: CreateTreeP
}

// generically show nice value for Balance type
if (isTypeBalance(_typeName)) {
if (isTypeBalanceWithBalanceCall(_typeName, name)) {
return handleBalanceDisplay({ value, decimals, unit, key })
}

Expand Down
9 changes: 6 additions & 3 deletions packages/ui/src/components/EasySetup/ManualExtrinsic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useApi } from '../../contexts/ApiContext'
import paramConversion from '../../utils/paramConversion'
import { getGlobalMaxValue, inputToBn } from '../../utils'
import BN from 'bn.js'
import { isTypeBalance } from '../../utils/isTypeBalance'
import { isTypeBalanceWithBalanceCall } from '../../utils/isTypeBalance'

interface Props {
extrinsicIndex?: string
Expand Down Expand Up @@ -160,7 +160,7 @@ const ManualExtrinsic = ({

// Deal with balance like types where the param needs to
// be multiplied by the token decimals
if (isTypeBalance(typeName)) {
if (isTypeBalanceWithBalanceCall(typeName, `${palletRpc}.${callable}`)) {
if (!isValidAmountString(value) || !chainInfo?.tokenDecimals) {
return previousValue
}
Expand Down Expand Up @@ -389,7 +389,10 @@ const ManualExtrinsic = ({
value={inputParams[ind] ? inputParams[ind].value : ''}
onChange={(event) => onParamChange(event, { ind, paramField })}
InputProps={{
endAdornment: isTypeBalance(paramField.typeName) && (
endAdornment: isTypeBalanceWithBalanceCall(
paramField.typeName,
`${palletRpc}.${callable}`
) && (
<InputAdornment position="end">{chainInfo?.tokenSymbol || ''}</InputAdornment>
)
}}
Expand Down
41 changes: 41 additions & 0 deletions packages/ui/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,44 @@ export const POLKADOT_SIGNING_METHODS = {
POLKADOT_SIGN_TRANSACTION: 'polkadot_signTransaction',
POLKADOT_SIGN_MESSAGE: 'polkadot_signMessage'
}

// from https://github.com/polkadot-js/apps/blob/acb87b52e52eda082b3d600abeadfed0f7ca3cc2/packages/react-params/src/overrides.ts#L4
export const balanceCalls = [
'auctions.bid',
'balances.forceTransfer',
'balances.forceUnreserve',
'balances.setBalance',
'balances.transfer',
'balances.transferAllowDeath',
'balances.transferKeepAlive',
'bounties.proposeBounty',
'bounties.proposeCurator',
'childBounties.proposeCurator',
'claims.mintClaim',
'convictionVoting.delegate',
'convictionVoting.vote',
'crowdloan.contribute',
'crowdloan.create',
'crowdloan.edit',
'democracy.delegate',
'democracy.propose',
'democracy.vote',
'identity.requestJudgement',
'identity.setFee',
'nominationPools.bondExtra',
'nominationPools.join',
'nominationPools.unbond',
'phragmenElection.vote',
'society.bid',
'society.vouch',
'staking.bond',
'staking.bondExtra',
'staking.rebond',
'staking.unbond',
'tips.tip',
'tips.tipNew',
'treasury.proposeSpend',
'treasury.spend',
'vesting.forceVestedTransfer',
'vesting.vestedTransfer'
]
9 changes: 7 additions & 2 deletions packages/ui/src/utils/isTypeBalance.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
export const isTypeBalance = (typeName?: string) =>
!!typeName && ['Balance', 'BalanceOf', 'Amount'].includes(typeName)
import { balanceCalls } from '../constants'

export const isTypeBalanceWithBalanceCall = (typeName?: string, call?: string) =>
!!typeName &&
!!call &&
['Balance', 'BalanceOf', 'Amount'].includes(typeName) &&
balanceCalls.includes(call)
Loading