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

BSC tokens and update ui kit format amount #961

Merged
merged 6 commits into from
Jul 8, 2024
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
2 changes: 1 addition & 1 deletion internal/handler/wallet/get_all_assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func getExpectedAssetsCount(t *testing.T) int {
counter := 0

for _, asset := range defaultAssets {
if asset.ChainID == 77658377 {
if asset.ChainID == 77658366 {
counter += 1
}
}
Expand Down
34 changes: 16 additions & 18 deletions pkg/assets/default_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,21 @@ const AssetsJSON = `[
"decimals": 18,
"MEXCSymbol": "USD",
"ChainID": 77658366
},
{
"address": "AS125oPLYRTtfVjpWisPZVTLjBhCFfQ1jDsi75XNtRm1NZux54eCj",
"name": "Wrapped Ether",
"symbol": "WETH.b",
"decimals": 18,
"MEXCSymbol": "ETHUSDT",
"ChainID": 77658377
},
{
"address": "AS12LKs9txoSSy8JgFJgV96m8k5z9pgzjYMYSshwN67mFVuj3bdUV",
"name": "Wrapped Binance USD",
"symbol": "USDT.b",
"decimals": 18,
"MEXCSymbol": "USD",
"ChainID": 77658377
}
]`

// TODO: add the following assets with the addresses
// {
// "address": "",
// "name": "Wrapped Ether",
// "symbol": "WETH.b",
// "decimals": 18,
// "MEXCSymbol": "ETHUSDT",
// "ChainID": 77658377
// },
// {
// "address": "",
// "name": "Wrapped Binance USD",
// "symbol": "USDT.b",
// "decimals": 18,
// "MEXCSymbol": "USD",
// "ChainID": 77658377
// },
6 changes: 3 additions & 3 deletions wails-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatStandard } from '@massalabs/react-ui-kit';
import { formatAmount } from '@massalabs/react-ui-kit';
import { massaToken } from '@massalabs/react-ui-kit/src/lib/massa-react/const';

import { OPER_BUY_ROLL } from '@/const/operations';
Expand Down Expand Up @@ -42,7 +42,7 @@ export function BuySellRoll(props: SignBodyProps) {
<div className="flex w-full items-center justify-between">
<p>{Intl.t(label)}</p>
<p>
{formatStandard(Coins)} {massaToken}
{formatAmount(Coins).full} {massaToken}
</p>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Args } from '@massalabs/massa-web3';
import { formatFTAmount } from '@massalabs/react-ui-kit';
import { formatAmount } from '@massalabs/react-ui-kit';
import { maskAddress } from '@massalabs/react-ui-kit/src/lib/massa-react/utils';
import { LogPrint } from '@wailsjs/runtime/runtime';

Expand Down Expand Up @@ -34,8 +34,7 @@ export function FTTransferInfo(props: FTTransferInfoProps) {
return (
<>
<AmountBox>
{formatFTAmount(amount, asset.decimals).amountFormattedFull}{' '}
{asset.symbol}
{formatAmount(amount, asset.decimals).full} {asset.symbol}
</AmountBox>

<div className="flex justify-between w-full">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tooltip, formatStandard } from '@massalabs/react-ui-kit';
import { Tooltip, formatAmount } from '@massalabs/react-ui-kit';
import { massaToken } from '@massalabs/react-ui-kit/src/lib/massa-react/const';
import { FiAlertTriangle, FiInfo } from 'react-icons/fi';

Expand Down Expand Up @@ -82,7 +82,7 @@ export function ExecuteSC(props: SignBodyProps) {
<p>{Intl.t('password-prompt.sign.max-coins')}</p>
</div>
<p>
{formatStandard(MaxCoins)} {massaToken}
{formatAmount(MaxCoins).full} {massaToken}
</p>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
InlineMoney,
Tooltip,
} from '@massalabs/react-ui-kit';
import { formatStandard } from '@massalabs/react-ui-kit';
import { formatAmount } from '@massalabs/react-ui-kit';
import { massaToken } from '@massalabs/react-ui-kit/src/lib/massa-react/const';
import BigNumber from 'bignumber.js';
import {
Expand Down Expand Up @@ -132,7 +132,7 @@ export function OperationCost(props: OperationCostProps) {
<div className="flex w-full justify-between pb-2">
<p>{Intl.t('password-prompt.sign.operation-const')}</p>
<p>
{formatStandard(operationCost)} {massaToken}
{formatAmount(operationCost).full} {massaToken}
</p>
</div>

Expand Down Expand Up @@ -200,7 +200,7 @@ export function OperationCost(props: OperationCostProps) {
<InlineMoney
customClass="mas-caption"
disabled
value={formatStandard(coins)}
value={formatAmount(coins).full}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatStandard } from '@massalabs/react-ui-kit';
import { formatAmount } from '@massalabs/react-ui-kit';
import { massaToken } from '@massalabs/react-ui-kit/src/lib/massa-react/const';

import Intl from '@/i18n/i18n';
Expand Down Expand Up @@ -43,7 +43,7 @@ export function Transaction(props: SignBodyProps) {
</div>

<AmountBox>
{formatStandard(Amount)} {massaToken}
{formatAmount(Amount).full} {massaToken}
</AmountBox>

<hr className="h-0.25 bg-neutral opacity-40 w-full" />
Expand Down
24 changes: 6 additions & 18 deletions web-frontend/cypress/e2e/acceptance/home/send.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('E2E | Acceptance | Home | Send', () => {

it('should render balance and amount should equal account balance', () => {
navigateToSendForm();
cy.get('[data-testid="available-amount"]').contains('1,000.000000000');
cy.get('[data-testid="available-amount"]').contains('1,000');
});

it('should send coins to address', () => {
Expand All @@ -136,7 +136,7 @@ describe('E2E | Acceptance | Home | Send', () => {

cy.get('[data-testid="send-confirmation"]').should(
'contain',
'550.123400000 MAS',
'550.1234 MAS',
);

cy.get('[data-testid="send-confirmation-recipient"]').contains(
Expand All @@ -153,28 +153,16 @@ describe('E2E | Acceptance | Home | Send', () => {
navigateToSendForm();

cy.get('[data-testid="send-percent-25"]').click();
cy.get('[data-testid="money-field"]').should(
'have.value',
'250.000000000',
);
cy.get('[data-testid="money-field"]').should('have.value', '250');

cy.get('[data-testid="send-percent-50"]').click();
cy.get('[data-testid="money-field"]').should(
'have.value',
'500.000000000',
);
cy.get('[data-testid="money-field"]').should('have.value', '500');

cy.get('[data-testid="send-percent-75"]').click();
cy.get('[data-testid="money-field"]').should(
'have.value',
'750.000000000',
);
cy.get('[data-testid="money-field"]').should('have.value', '750');

cy.get('[data-testid="send-percent-100"]').click();
cy.get('[data-testid="money-field"]').should(
'have.value',
'999.990000000',
);
cy.get('[data-testid="money-field"]').should('have.value', '999.99');
server.trackRequest = false;
});

Expand Down
6 changes: 3 additions & 3 deletions web-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web-frontend/src/pages/AccountSelect/AccountSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function AccountSelect() {
}, [accounts, navigate, hasAccounts, error, isLoading]);

function getFormattedBalance(account: AccountObject): string {
return formatAmount(account.candidateBalance).amountFormattedFull;
return formatAmount(account.candidateBalance).full;
}

return (
Expand Down
4 changes: 1 addition & 3 deletions web-frontend/src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export default function Home() {

const unformattedBalance = account?.candidateBalance ?? '0';
const balance = parseInt(unformattedBalance);
const formattedBalance = formatAmount(
balance.toString(),
).amountFormattedPreview;
const formattedBalance = formatAmount(balance.toString()).preview;

return (
<WalletLayout menuItem={MenuItem.Home}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ function GenerateLink(props: GenerateLinkProps) {
const [selectedAsset, setSelectedAsset] = useState<Asset | undefined>();

const formattedBalance = selectedAsset
? formatAmount(selectedAsset.balance || '', selectedAsset.decimals)
.amountFormattedFull
? formatAmount(selectedAsset.balance || '', selectedAsset.decimals).full
: '';

function validate(formObject: MoneyForm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function AssetSelector(props: AssetSelectorProps) {
const formattedBalance = formatAmount(
asset.balance || '',
asset.decimals,
).amountFormattedFull;
).full;
return {
itemPreview: asset.symbol,
item: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ function AccountSelect(props: ContactListProps) {
posIcon={<MassaLogo size={24} />}
content={maskNickname(filteredAccount.nickname)}
variant="secondary"
amount={
formatAmount(filteredAccount.candidateBalance)
.amountFormattedFull
}
amount={formatAmount(filteredAccount.candidateBalance).full}
onClick={() => handleSetRecipient(filteredAccount)}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Balance,
Button,
Tooltip,
formatFTAmount,
formatAmount,
parseAmount,
Clipboard,
Mns,
Expand Down Expand Up @@ -43,11 +43,11 @@ export function SendConfirmation(props: SendConfirmationProps) {
const formattedRecipientAddress = maskAddress(recipientAddress);
// amount is the value given by the Money input component
// we convert to the smallest unit with parseAmount
// and then format it with formatFTAmount
const formattedAmount = formatFTAmount(
// and then format it with formatAmount
const formattedAmount = formatAmount(
parseAmount(amount, data.asset.decimals),
decimals,
).amountFormattedFull;
).full;

let selectedFees;

Expand Down
7 changes: 1 addition & 6 deletions web-frontend/src/pages/TransferCoins/SendCoins/SendForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,7 @@ export function SendForm(props: SendFormProps) {
}

const formattedBalance = selectedAsset?.balance ? (
<u>
{
formatAmount(selectedAsset.balance, selectedAsset.decimals)
.amountFormattedFull
}
</u>
<u>{formatAmount(selectedAsset.balance, selectedAsset.decimals).full}</u>
) : (
<Spinner size={12} customClass="inline-block" />
);
Expand Down
2 changes: 1 addition & 1 deletion web-frontend/src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ export function handlePercent(
}
}

return formatAmount(newAmount.toString(), decimals).amountFormattedFull;
return formatAmount(newAmount.toString(), decimals).full;
}
Loading