base-v1.6.0 to base-v1.7.0
Since the release of v1.7.0
we have removed formatDenom
in favor of formatToken
and formatNumber
.
Due to the limit of js being js and how denoms can have as much as 18 decimal places, we have switched over to Big.js and converted all base messages with MsgCoin
type to save the amount as a string
.
The following global type declaraction has been updated:
// before
type TokenUnit = {
value: number;
denom: string;
format: string;
}
// after
type TokenUnit = {
displayDenom: string;
baseDenom: string;
exponent: number;
value: string;
}
Update your chain's base branch
$ git fetch --tags
$ git checkout <your chain base>
$ git checkout -b merge/v1.7.0
$ git merge base-v1.7.0
Fix all merge conflicts.
If you want to keep formatDenom do not delete the file. Fix the merge while keeping the file and you should be good to go
Update custom messages
By default, the only places the need updating should be custom messages. In your IDE search for files containing formatToken
If it is a custom tx like the following:
import React from 'react';
import Trans from 'next-translate/Trans';
import useTranslation from 'next-translate/useTranslation';
import numeral from 'numeral';
import { Typography } from '@material-ui/core';
import { Name } from '@components';
import { formatDenom } from '@utils/format_denom';
import { MsgBurnTokens } from '@models';
import { useProfileRecoil } from '@recoil/profiles';
const BurnTokens = (props: {
message: MsgBurnTokens;
}) => {
const { message } = props;
const { t } = useTranslation('transactions');
const liquidityProvider = useProfileRecoil(message.liquidityProvider);
const liqdPvdMoniker = liquidityProvider ? liquidityProvider?.name : message.liquidityProvider;
const amountBeforeParse = message.amount;
const parsedAmount = amountBeforeParse.map((x) => {
const eachAmount = formatDenom(x.amount, x.denom);
return `${numeral(eachAmount.value).format('0,0.[000000]')} ${eachAmount.denom.toUpperCase()}`;
});
const finalData = parsedAmount.reduce((text, value, i, array) => text + (i < array.length - 1 ? ', ' : ` ${t(' and ')} `) + value);
return (
<Typography>
<Trans
i18nKey="message_contents:txBurnTokens"
components={[
(
<Name
address={message.liquidityProvider}
name={liqdPvdMoniker}
/>
),
<b />,
]}
values={{
amount: finalData,
}}
/>
</Typography>
);
};
export default BurnTokens;
Remove import numeral from 'numeral';
(leave the import if absolutely necessary)
Remove import { formatDenom } from '@utils/format_denom';
Import import { formatToken, formatNumber} from '@utils/format_token';
Replace all occurance of formatDenom
to formatToken
Replace ${numeral(eachAmount.value).format('0,0.[000000]')} ${eachAmount.denom.toUpperCase()}
to ${formatNumber(eachAmount.value, eachAmount.exponent)} ${eachAmount.displayDenom.toUpperCase()}
The final results should be something like the following:
import React from 'react';
import Trans from 'next-translate/Trans';
import useTranslation from 'next-translate/useTranslation';
import { Typography } from '@material-ui/core';
import { Name } from '@components';
import {
formatToken, formatNumber,
} from '@utils/format_token';
import { MsgBurnTokens } from '@models';
import { useProfileRecoil } from '@recoil/profiles';
const BurnTokens = (props: {
message: MsgBurnTokens;
}) => {
const { message } = props;
const { t } = useTranslation('transactions');
const liquidityProvider = useProfileRecoil(message.liquidityProvider);
const liqdPvdMoniker = liquidityProvider ? liquidityProvider?.name : message.liquidityProvider;
const amountBeforeParse = message.amount;
const parsedAmount = amountBeforeParse.map((x) => {
const eachAmount = formatToken(x.amount, x.denom);
return `${formatNumber(eachAmount.value, eachAmount.exponent)} ${eachAmount.displayDenom.toUpperCase()}`;
});
const finalData = parsedAmount.reduce((text, value, i, array) => text + (i < array.length - 1 ? ', ' : ` ${t(' and ')} `) + value);
return (
<Typography>
<Trans
i18nKey="message_contents:txBurnTokens"
components={[
(
<Name
address={message.liquidityProvider}
name={liqdPvdMoniker}
/>
),
<b />,
]}
values={{
amount: finalData,
}}
/>
</Typography>
);
};
export default BurnTokens;
Clean up
Review that formatToken
is no longer being used. Feel free to open up an issue if you have questions.