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

display native token as displat denom #187

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading