Skip to content

Commit

Permalink
fix: fix up IBC amount input (#1281)
Browse files Browse the repository at this point in the history
Fixes #1271.

- Use empty input with placeholder instead of default 0 value
- Check for max decimal places allowed by selected asset
  • Loading branch information
emccorson committed Nov 21, 2024
1 parent 4c30598 commit 2f6b52f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions apps/namadillo/src/App/Transfer/TransferSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ export type TransferSourceProps = {
onChangeShielded?: (isShielded: boolean) => void;
};

const amountMaxDecimalPlaces = (asset?: Asset): number | undefined => {
if (typeof asset !== "undefined") {
for (const { denom, exponent } of asset.denom_units) {
if (denom === asset.display) {
return exponent;
}
}
}
return undefined;
};

export const TransferSource = ({
chain,
asset,
Expand Down Expand Up @@ -91,8 +102,10 @@ export const TransferSource = ({
"[&_input]:!border-0 [&_input]:px-0"
)}
disabled={!chain || !asset}
value={amount || new BigNumber(0)}
onChange={(e) => onChangeAmount && onChangeAmount(e.target.value)}
value={amount}
onChange={(e) => onChangeAmount?.(e.target.value)}
placeholder="Amount"
maxDecimalPlaces={amountMaxDecimalPlaces(asset)}
/>
</div>
{asset && availableAmount && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("Component: TransferSource", () => {
const assetControl = getEmptyAsset();
fireEvent.click(assetControl);
expect(openAssetSelectorMock).not.toHaveBeenCalled();
const amountInput = screen.getByDisplayValue("0");
const amountInput = screen.getByPlaceholderText("Amount");
expect(amountInput).toBeDisabled();
});

Expand Down

1 comment on commit 2f6b52f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.