Skip to content

Commit

Permalink
Merge pull request #187 from notional-labs/add_select_token_to_send
Browse files Browse the repository at this point in the history
display native token as displat denom
  • Loading branch information
sontrinh16 authored Nov 15, 2023
2 parents c0ba1c4 + cf066d9 commit b82faf2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions components/data_view/TransactionInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const TransactionInfo = ({ tx, txHash, chain }) => {
jsx = <TransferMsg
msg={msg}
parentStyle={style}
chain={chain}
/>
break;
case "/cosmos.staking.v1beta1.MsgDelegate":
Expand Down
8 changes: 4 additions & 4 deletions components/data_view/transaction/TransferMsg.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getValueFromDenom, getDisplayDenom, denomShortender } from "../../../libs/stringConvert"
import { getValueFromDenom, getDisplayDenom, denomShortender, getDisplayValueWithChainInfo, getDisplayDenomWithChainInfo } from "../../../libs/stringConvert"
import { motion } from "framer-motion"

const style = {
Expand All @@ -14,7 +14,7 @@ const style = {
}
}

const TransferMsg = ({ parentStyle, msg }) => {
const TransferMsg = ({ parentStyle, msg, chain }) => {
return (
<>
<div
Expand All @@ -40,8 +40,8 @@ const TransferMsg = ({ parentStyle, msg }) => {
style.value
}
>
{`${msg.value.amount.length > 0 && msg.value.amount[0].amount} `}
{msg.value.amount.length > 0 && denomShortender(msg.value.amount[0].denom.toUpperCase())}
{`${msg.value.amount.length > 0 && getDisplayValueWithChainInfo(msg.value.amount[0].amount, msg.value.amount[0].denom, chain)} `}
{msg.value.amount.length > 0 && denomShortender(getDisplayDenomWithChainInfo(msg.value.amount[0].denom, chain).toUpperCase())}
</motion.div>
</div>
<div
Expand Down
13 changes: 9 additions & 4 deletions components/form/transaction/SendMsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import Input from "../../input/Input"
import { isValidAddress } from "../../../libs/checkTool";
import { openNotification } from "../../ulti/Notification";
import { createSendMsg, } from "../../../libs/transaction";
import { denomShortender } from "../../../libs/stringConvert";
import { denomShortender,
getDisplayDenomWithChainInfo,
getDisplayValueWithChainInfo,
getValueWithChainInfo} from "../../../libs/stringConvert";
import Button from "../../input/Button";
import { InputNumber } from 'antd';

Expand Down Expand Up @@ -46,7 +49,7 @@ const SendMsgForm = ({ address, chain, style, msgs, setMsgs, balances }) => {
const msg = createSendMsg(
address,
txBody.toAddress,
txBody.amount,
getValueWithChainInfo(txBody.amount, balances[selectedToken].denom, chain),
balances[selectedToken].denom
)
setMsgs([...msgs, msg])
Expand Down Expand Up @@ -121,7 +124,8 @@ const SendMsgForm = ({ address, chain, style, msgs, setMsgs, balances }) => {
value={index}
key={index}
>
{`${balance.amount} ${balance.denom}`}
{`${getDisplayValueWithChainInfo(balance.amount, balance.denom, chain)}
${getDisplayDenomWithChainInfo(balance.denom, chain)}`}
</option>
)
})
Expand All @@ -146,7 +150,8 @@ const SendMsgForm = ({ address, chain, style, msgs, setMsgs, balances }) => {
margin: 0
}}
>
{`Amount (${balances.length > 0 && denomShortender(balances[selectedToken].denom).toUpperCase()})`}
{`Amount (${balances.length > 0
&& denomShortender(getDisplayDenomWithChainInfo(balances[selectedToken].denom, chain)).toUpperCase()})`}
</h4>
<InputNumber
onChange={handleInputNumber}
Expand Down
23 changes: 23 additions & 0 deletions libs/stringConvert.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ export const getDisplayDenom = (denom) => {
}
}

export const getDisplayDenomWithChainInfo = (denom, chain) => {
if (denom === chain.denom) {
return chain.displayDenom
}
return denom
}

export const getDisplayValueWithChainInfo = (value, denom, chain) => {
if (denom === chain.denom) {
return getValueFromDenom(denom, value)
}
return value
}

export const getValueWithChainInfo = (value, denom, chain) => {
if (denom === chain.denom) {
return convertValueFromDenom(chain.base_denom, value)
}
return value
}



export const getValueFromDenom = (denom, value) => {
let convertValue
if (denom in specialDenom) {
Expand Down

0 comments on commit b82faf2

Please sign in to comment.