Skip to content

Commit

Permalink
Ensure Msg requests in token are rounded to minimum denom integers
Browse files Browse the repository at this point in the history
  • Loading branch information
dib542 committed Aug 3, 2022
1 parent 06e8bd4 commit 6ac3624
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ REACT_APP__CHAIN_ID=duality
REACT_APP__CHAIN_NAME=Duality testnet
REACT_APP__COIN_DENOM=COSMOS
REACT_APP__COIN_MIN_DENOM=token
REACT_APP__COIN_MIN_DENOM_EXP=1E-18
REACT_APP__REST_API=http://localhost:1317
REACT_APP__RPC_API=http://localhost:26657
REACT_APP__WEBSOCKET_URL=ws://localhost:26657/websocket
12 changes: 8 additions & 4 deletions src/pages/Swap/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { useSwap } from './hooks/useSwap';

import './Swap.scss';

const { REACT_APP__COIN_MIN_DENOM_EXP = '0' } = process.env;
const denomExponent = parseFloat(REACT_APP__COIN_MIN_DENOM_EXP);

export default function Swap() {
const { address } = useWeb3();
const { data: tokenList = [], isValidating: isValidaingTokens } = useTokens();
Expand Down Expand Up @@ -68,12 +71,13 @@ export default function Swap() {
if (address && routerResult) {
// convert to swap request format
const result = routerResult;
// Cosmos requires tokens in integer format of smallest denomination
setSwapRequest({
amountIn: result.amountIn.toString(),
tokenIn: result.tokenIn.toString(),
tokenOut: result.tokenOut.toString(),
amountIn: result.amountIn.toFixed(denomExponent),
tokenIn: result.tokenIn,
tokenOut: result.tokenOut,
// TODO: add tolerance factor
minOut: result.amountOut.toString(),
minOut: result.amountOut.toFixed(denomExponent),
creator: address,
});
}
Expand Down

0 comments on commit 6ac3624

Please sign in to comment.