Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaut committed Jan 28, 2025
1 parent ad7aece commit 13720d4
Showing 1 changed file with 5 additions and 27 deletions.
32 changes: 5 additions & 27 deletions packages/ui/src/components/EasySetup/BalancesTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { isContextIn, isContextOf, useApi } from '../../contexts/ApiContext'
import { useCheckBalance } from '../../hooks/useCheckBalance'
import { inputToBigInt, getGlobalMaxValue } from '../../utils/bnUtils'
import { Select, TextField } from '../library'
import { getOptionLabel } from '../../utils/getOptionLabel'
import { useAccountBaseFromAccountList } from '../../hooks/useAccountBaseFromAccountList'
import { MultiAddress } from '@polkadot-api/descriptors'
import { Transaction } from 'polkadot-api'
Expand Down Expand Up @@ -96,6 +95,8 @@ const BalancesTransfer = ({ className, onSetExtrinsic, onSetErrorMessage, from }
return
}

// not re-using isAssetHub here bc TS doesn't type correctly
// if we're on AH and *not* sending the native asset use Assets.transfer_keep_alive
if (isContextIn(ctx, assetHubKeys) && selectedAsset.symbol !== chainInfo?.tokenSymbol) {
const extrinsic = ctx.api.tx.Assets.transfer_keep_alive({
amount,
Expand All @@ -104,6 +105,8 @@ const BalancesTransfer = ({ className, onSetExtrinsic, onSetErrorMessage, from }
})

!!extrinsic && onSetExtrinsic(extrinsic)

// we're on AH and sending the native asset use Balances.transfer
} else {
const extrinsic = isContextOf(ctx, 'hydration')
? ctx.api.tx.Balances.transfer_keep_alive({
Expand Down Expand Up @@ -137,22 +140,14 @@ const BalancesTransfer = ({ className, onSetExtrinsic, onSetErrorMessage, from }
useEffect(() => {
if (!selectedAsset || !amountString) return

const decimals = selectedAsset.decimals

if (!decimals) {
onSetErrorMessage('Invalid network decimals')
setAmount(0n)
return
}

if (!amountString.match('^[0-9]+([.][0-9]+)?$')) {
setAmountError('Only numbers and "." are accepted.')
onSetErrorMessage('Invalid amount')
setAmount(0n)
return
}

const bigintResult = inputToBigInt(decimals, amountString)
const bigintResult = inputToBigInt(selectedAsset.decimals, amountString)

if (bigintResult > maxValue) {
setAmountError('Amount too large')
Expand All @@ -174,21 +169,6 @@ const BalancesTransfer = ({ className, onSetExtrinsic, onSetErrorMessage, from }
[onSetErrorMessage]
)

const onInputChange = useCallback(
(
_: React.SyntheticEvent<Element, Event>,
val: NonNullable<
string | AccountBaseInfo | (string | AccountBaseInfo | undefined)[] | undefined
>
) => {
const value = getOptionLabel(val as string)

if (!value) {
setSelected(undefined)
}
},
[]
)
const onAssetSelection = useCallback(
(event: SelectChangeEvent<unknown>) => {
const selectedSymbol = event.target.value as string
Expand All @@ -209,7 +189,6 @@ const BalancesTransfer = ({ className, onSetExtrinsic, onSetErrorMessage, from }
<SelectStyled
value={selectedAsset.symbol}
onChange={onAssetSelection}
fullWidth
menuItems={assetList.map(({ logo, symbol }) => ({ value: symbol, logo }))}
testId="ah-assets"
upperCase
Expand All @@ -225,7 +204,6 @@ const BalancesTransfer = ({ className, onSetExtrinsic, onSetErrorMessage, from }
value={selected}
label="to"
allowAnyAddressInput={true}
onInputChange={onInputChange}
accountList={accountBase}
testId="send-tokens-field-to"
/>
Expand Down

0 comments on commit 13720d4

Please sign in to comment.