Skip to content

Commit

Permalink
refactor(tooling): rename subunit to nano (#1656)
Browse files Browse the repository at this point in the history
* refactor(tooling): rename subunit to nano

* refactor(tooling): rename subunit to nano
  • Loading branch information
begonaalvarezd authored Aug 13, 2024
1 parent f097ffa commit 21befe0
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 61 deletions.
36 changes: 18 additions & 18 deletions apps/core/src/hooks/__tests__/useFormatCoin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CoinFormat, formatBalance } from '../useFormatCoin';

const IOTA_DECIMALS = 9;

function toMicros(iota: string) {
function toNano(iota: string) {
return new BigNumber(iota).shiftedBy(IOTA_DECIMALS).toString();
}

Expand All @@ -25,36 +25,36 @@ describe('formatBalance', () => {
});

it('formats integer amounts correctly', () => {
expect(formatBalance(toMicros('1'), IOTA_DECIMALS)).toEqual('1');
expect(formatBalance(toMicros('1.0001'), IOTA_DECIMALS)).toEqual('1');
expect(formatBalance(toMicros('1.1201'), IOTA_DECIMALS)).toEqual('1.12');
expect(formatBalance(toMicros('1.1234'), IOTA_DECIMALS)).toEqual('1.12');
expect(formatBalance(toMicros('1.1239'), IOTA_DECIMALS)).toEqual('1.12');
expect(formatBalance(toNano('1'), IOTA_DECIMALS)).toEqual('1');
expect(formatBalance(toNano('1.0001'), IOTA_DECIMALS)).toEqual('1');
expect(formatBalance(toNano('1.1201'), IOTA_DECIMALS)).toEqual('1.12');
expect(formatBalance(toNano('1.1234'), IOTA_DECIMALS)).toEqual('1.12');
expect(formatBalance(toNano('1.1239'), IOTA_DECIMALS)).toEqual('1.12');

expect(formatBalance(toMicros('9999.9999'), IOTA_DECIMALS)).toEqual('9,999.99');
expect(formatBalance(toNano('9999.9999'), IOTA_DECIMALS)).toEqual('9,999.99');
// 10k + handling:
expect(formatBalance(toMicros('10000'), IOTA_DECIMALS)).toEqual('10 K');
expect(formatBalance(toMicros('12345'), IOTA_DECIMALS)).toEqual('12.34 K');
expect(formatBalance(toNano('10000'), IOTA_DECIMALS)).toEqual('10 K');
expect(formatBalance(toNano('12345'), IOTA_DECIMALS)).toEqual('12.34 K');
// Millions:
expect(formatBalance(toMicros('1234000'), IOTA_DECIMALS)).toEqual('1.23 M');
expect(formatBalance(toNano('1234000'), IOTA_DECIMALS)).toEqual('1.23 M');
// Billions:
expect(formatBalance(toMicros('1234000000'), IOTA_DECIMALS)).toEqual('1.23 B');
expect(formatBalance(toNano('1234000000'), IOTA_DECIMALS)).toEqual('1.23 B');
});

it('formats integer amounts with full CoinFormat', () => {
expect(formatBalance(toMicros('1'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual('1');
expect(formatBalance(toMicros('1.123456789'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual(
expect(formatBalance(toNano('1'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual('1');
expect(formatBalance(toNano('1.123456789'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual(
'1.123456789',
);
expect(formatBalance(toMicros('9999.9999'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual(
expect(formatBalance(toNano('9999.9999'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual(
'9,999.9999',
);
expect(formatBalance(toMicros('10000'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual('10,000');
expect(formatBalance(toMicros('12345'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual('12,345');
expect(formatBalance(toMicros('1234000'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual(
expect(formatBalance(toNano('10000'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual('10,000');
expect(formatBalance(toNano('12345'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual('12,345');
expect(formatBalance(toNano('1234000'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual(
'1,234,000',
);
expect(formatBalance(toMicros('1234000000'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual(
expect(formatBalance(toNano('1234000000'), IOTA_DECIMALS, CoinFormat.FULL)).toEqual(
'1,234,000,000',
);
});
Expand Down
4 changes: 2 additions & 2 deletions apps/explorer/src/components/gas-breakdown/GasBreakdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function GasAmount({ amount }: GasProps): JSX.Element | null {

<div className="flex flex-wrap items-center text-body font-medium text-steel">
({BigInt(amount)?.toLocaleString()}
<div className="ml-0.5 text-subtitleSmall font-medium text-steel">MICROS</div>)
<div className="ml-0.5 text-subtitleSmall font-medium text-steel">nano</div>)
</div>
</div>
);
Expand Down Expand Up @@ -74,7 +74,7 @@ function TotalGasAmount({ amount }: GasProps): JSX.Element | null {
{BigInt(amount)?.toLocaleString()}
</Heading>
<Text variant="body/medium" color="steel">
MICROS
nano
</Text>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/src/components/home-metrics/OnTheNetwork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function OnTheNetwork(): JSX.Element {
orientation="horizontal"
label="Reference Gas Price"
tooltip="The reference gas price of the current epoch"
postfix={gasPriceFormatted !== null ? 'MICROS' : null}
postfix={gasPriceFormatted !== null ? 'nano' : null}
size="sm"
>
{gasPriceFormatted}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ import { Text } from '@iota/ui';
type StakeColumnProps = {
stake: bigint | number | string;
hideCoinSymbol?: boolean;
inMICROS?: boolean;
inNano?: boolean;
};

export function StakeColumn({
stake,
hideCoinSymbol,
inMICROS = false,
inNano = false,
}: StakeColumnProps): JSX.Element {
const coinFormat = hideCoinSymbol ? CoinFormat.FULL : CoinFormat.ROUNDED;
const [amount, symbol] = useFormatCoin(stake, IOTA_TYPE_ARG, coinFormat);
return (
<div className="flex items-end gap-0.5">
<Text variant="bodySmall/medium" color="steel-darker">
{inMICROS ? formatBalance(stake, 0, coinFormat) : amount}
{inNano ? formatBalance(stake, 0, coinFormat) : amount}
</Text>
{!hideCoinSymbol && (
<Text variant="captionSmall/medium" color="steel-dark">
{inMICROS ? 'MICROS' : symbol}
{inNano ? 'nano' : symbol}
</Text>
)}
</div>
Expand Down
8 changes: 4 additions & 4 deletions apps/explorer/src/components/validator/DelegationAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import { Heading, Text } from '@iota/ui';
type DelegationAmountProps = {
amount: bigint | number | string;
isStats?: boolean;
inMICROS?: boolean;
inNano?: boolean;
};

export function DelegationAmount({
amount,
isStats,
inMICROS = false,
inNano = false,
}: DelegationAmountProps): JSX.Element {
const [formattedAmount, symbol] = useFormatCoin(amount, IOTA_TYPE_ARG);
const delegationAmount = inMICROS ? formatBalance(amount, 0, CoinFormat.FULL) : formattedAmount;
const delegationSymbol = inMICROS ? 'MICROS' : symbol;
const delegationAmount = inNano ? formatBalance(amount, 0, CoinFormat.FULL) : formattedAmount;
const delegationSymbol = inNano ? 'nano' : symbol;
return isStats ? (
<div className="flex items-end gap-1.5 break-all">
<Heading as="div" variant="heading3/semibold" color="steel-darker">
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/src/components/validator/ValidatorStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function ValidatorStats({
<DelegationAmount
amount={validatorData.nextEpochGasPrice}
isStats
inMICROS
inNano
/>
</Stats>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/src/pages/epochs/stats/ValidatorStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function ValidatorStatus(): JSX.Element | null {
{nextRefGasPrice.toString()}
</Heading>
<Text variant="pBody/medium" color="steel-darker">
MICROS
nano
</Text>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/src/pages/validators/Validators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function validatorsTableData(
header: 'Proposed Next Epoch Gas Price',
accessorKey: 'nextEpochGasPrice',
enableSorting: true,
cell: (props: any) => <StakeColumn stake={props.getValue()} inMICROS />,
cell: (props: any) => <StakeColumn stake={props.getValue()} inNano />,
},
{
header: 'APY',
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet/src/ui/app/pages/home/tokens/TokenLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { CoinItem } from '_components/active-coins-card/CoinItem';
import { ampli } from '_src/shared/analytics/ampli';
import { type CoinBalance } from '@iota/iota-sdk/client';
import { MICROS_PER_IOTA } from '@iota/iota-sdk/utils';
import { NANO_PER_IOTA } from '@iota/iota-sdk/utils';
import { type ReactNode } from 'react';
import { Link } from 'react-router-dom';

Expand All @@ -22,7 +22,7 @@ export function TokenLink({ coinBalance, centerAction, subtitle }: TokenLinkProp
onClick={() =>
ampli.selectedCoin({
coinType: coinBalance.coinType,
totalBalance: Number(BigInt(coinBalance.totalBalance) / MICROS_PER_IOTA),
totalBalance: Number(BigInt(coinBalance.totalBalance) / NANO_PER_IOTA),
})
}
key={coinBalance.coinType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import { useIotaClientQuery } from '@iota/dapp-kit';
import { ArrowLeft16, StakeAdd16, StakeRemove16 } from '@iota/icons';
import { Network, type StakeObject } from '@iota/iota-sdk/client';
import { MICROS_PER_IOTA, IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import { NANO_PER_IOTA, IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import BigNumber from 'bignumber.js';
import { useMemo } from 'react';

Expand Down Expand Up @@ -251,7 +251,7 @@ export function DelegationDetailCard({ validatorAddress, stakedId }: DelegationD
to={stakeByValidatorAddress + '&unstake=true'}
onClick={() => {
ampli.clickedUnstakeIota({
stakedAmount: Number(totalStake / MICROS_PER_IOTA),
stakedAmount: Number(totalStake / NANO_PER_IOTA),
validatorAddress,
});
}}
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet/src/ui/app/staking/stake/StakingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
import { useIotaClientQuery } from '@iota/dapp-kit';
import { ArrowLeft16 } from '@iota/icons';
import type { StakeObject } from '@iota/iota-sdk/client';
import { MICROS_PER_IOTA, IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import { NANO_PER_IOTA, IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
// import * as Sentry from '@sentry/react';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { Formik } from 'formik';
Expand Down Expand Up @@ -147,7 +147,7 @@ function StakingCard() {
},
onSuccess: (_, { amount, validatorAddress }) => {
ampli.stakedIota({
stakedAmount: Number(amount / MICROS_PER_IOTA),
stakedAmount: Number(amount / NANO_PER_IOTA),
validatorAddress: validatorAddress,
});
},
Expand Down
12 changes: 6 additions & 6 deletions dapps/kiosk-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
formatAddress,
isValidIotaAddress,
isValidIotaObjectId,
MICROS_PER_IOTA,
NANO_PER_IOTA,
} from '@iota/iota-sdk/utils';
import { bcs } from '@iota/iota-sdk/bcs';
import { program } from 'commander';
Expand Down Expand Up @@ -118,7 +118,7 @@ program
.command('list')
.description('list an item in the Kiosk for the specified amount of IOTA')
.argument('<item ID>', 'The ID of the item to list')
.argument('<amount MICROS>', 'The amount of IOTA to list the item for')
.argument('<amount nano>', 'The amount of IOTA to list the item for')
.action(listItem);

program
Expand Down Expand Up @@ -764,7 +764,7 @@ async function sendTx(txb) {
console.log('Storage rebate: %s', gas.storageRebate);
console.log('NonRefundable Storage Fee: %s', gas.nonRefundableStorageFee);
console.log(
'Total Gas: %s IOTA (%s MICROS)',
'Total Gas: %s IOTA (%s nano)',
formatAmount(total),
total.toString(),
);
Expand Down Expand Up @@ -792,15 +792,15 @@ function formatType(type) {
}

/**
* Formats the MICROS into IOTA.
* Formats the nano into IOTA.
*/
function formatAmount(amount) {
if (!amount) {
return null;
}

if (amount <= MICROS_PER_IOTA) {
return Number(amount) / Number(MICROS_PER_IOTA);
if (amount <= NANO_PER_IOTA) {
return Number(amount) / Number(NANO_PER_IOTA);
}

let len = amount.toString().length;
Expand Down
4 changes: 2 additions & 2 deletions dapps/kiosk/src/components/DisplayObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { KioskListing } from '@iota/kiosk';
import { ReactNode } from 'react';

import { DEFAULT_IMAGE } from '../utils/constants';
import { formatIota, microsToIota } from '../utils/utils';
import { formatIota, nanoToIota } from '../utils/utils';
import { OwnedObjectType } from './Inventory/OwnedObjects';
import { ItemLockedBadge } from './Kiosk/ItemLockedBadge';

Expand All @@ -20,7 +20,7 @@ export interface DisplayObject {
export function DisplayObject({ item, listing = null, children }: DisplayObject) {
const currentAccount = useCurrentAccount();

const price = formatIota(microsToIota(listing?.price));
const price = formatIota(nanoToIota(listing?.price));

return (
<div className="border relative border-gray-400 overflow-hidden text-center flex justify-between flex-col rounded-lg">
Expand Down
4 changes: 2 additions & 2 deletions dapps/kiosk/src/components/Kiosk/KioskData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { toast } from 'react-hot-toast';
import { useKioskDetails } from '../../hooks/kiosk';
import { useWithdrawMutation } from '../../mutations/kiosk';
import { TANSTACK_KIOSK_DATA_KEY } from '../../utils/constants';
import { formatIota, microsToIota } from '../../utils/utils';
import { formatIota, nanoToIota } from '../../utils/utils';
import { Button } from '../Base/Button';
import { ExplorerLink } from '../Base/ExplorerLink';
import { Loading } from '../Base/Loading';
Expand All @@ -33,7 +33,7 @@ export function KioskData({ kioskId }: { kioskId: string }) {
},
});

const profits = formatIota(microsToIota(kiosk?.profits));
const profits = formatIota(nanoToIota(kiosk?.profits));

if (isPending) return <Loading />;
return (
Expand Down
4 changes: 2 additions & 2 deletions dapps/kiosk/src/components/Modals/ListPrice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { MICROS_PER_IOTA } from '@iota/iota-sdk/utils';
import { NANO_PER_IOTA } from '@iota/iota-sdk/utils';
import { useState } from 'react';

import { usePlaceAndListMutation } from '../../mutations/kiosk';
Expand Down Expand Up @@ -52,7 +52,7 @@ export function ListPrice({ item, onSuccess, closeModal, listAndPlace, kioskId }
onClick={() =>
placeAndListToKioskMutation.mutate({
item,
price: (Number(price) * Number(MICROS_PER_IOTA)).toString(),
price: (Number(price) * Number(NANO_PER_IOTA)).toString(),
shouldPlace: listAndPlace,
kioskId,
})
Expand Down
8 changes: 4 additions & 4 deletions dapps/kiosk/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { KioskListing, KioskOwnerCap } from '@iota/kiosk';
import { IotaObjectResponse } from '@iota/iota-sdk/client';
import { MICROS_PER_IOTA, normalizeIotaAddress } from '@iota/iota-sdk/utils';
import { NANO_PER_IOTA, normalizeIotaAddress } from '@iota/iota-sdk/utils';

// Parse the display of a list of objects into a simple {object_id: display} map
// to use throughout the app.
Expand Down Expand Up @@ -32,9 +32,9 @@ export const processKioskListings = (data: KioskListing[]): Record<string, Kiosk
return results;
};

export const microsToIota = (micros: bigint | string | undefined) => {
if (!micros) return 0;
return Number(micros || 0) / Number(MICROS_PER_IOTA);
export const nanoToIota = (nano: bigint | string | undefined) => {
if (!nano) return 0;
return Number(nano || 0) / Number(NANO_PER_IOTA);
};

export const formatIota = (amount: number) => {
Expand Down
6 changes: 3 additions & 3 deletions sdk/kiosk/src/client/kiosk-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class KioskTransaction {
* A function to place an item in the kiosk and list it for sale in one transaction.
* @param itemType The type `T` of the item
* @param item The ID or Transaction Argument of the item
* @param price The price in MICROS
* @param price The price in nano
*/
placeAndList({ itemType, item, price }: ItemReference & Price) {
this.#validateKioskIsSet();
Expand All @@ -245,7 +245,7 @@ export class KioskTransaction {
* A function to list an item in the kiosk.
* @param itemType The type `T` of the item
* @param itemId The ID of the item
* @param price The price in MICROS
* @param price The price in nano
*/
list({ itemType, itemId, price }: ItemId & { price: string | bigint }) {
this.#validateKioskIsSet();
Expand Down Expand Up @@ -321,7 +321,7 @@ export class KioskTransaction {
* Can be called like: `const [item, transferRequest] = kioskTx.purchase({...})`
* @param itemType The type `T` of the item
* @param itemId The ID of the item
* @param price The price in MICROS
* @param price The price in nano
* @param sellerKiosk The kiosk which is selling the item. Can be an id or an object argument.
*/
purchase({
Expand Down
4 changes: 2 additions & 2 deletions sdk/kiosk/src/client/tp-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class TransferPolicyTransaction {
* (but you should define at least one of them for the rule to make sense).
*
* @param percentageBps The royalty percentage in basis points. Use `percentageToBasisPoints` helper to convert from percentage [0,100].
* @param minAmount The minimum royalty amount per request in MICROS.
* @param minAmount The minimum royalty amount per request in nano.
*/
addRoyaltyRule(
percentageBps: number | string, // this is in basis points.
Expand Down Expand Up @@ -221,7 +221,7 @@ export class TransferPolicyTransaction {

/**
* A function to add the floor price rule to a transfer policy.
* @param minPrice The minimum price in MICROS.
* @param minPrice The minimum price in nano.
*/
addFloorPriceRule(minPrice: string | bigint) {
this.#validateInputs();
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ console.log({ result });

### Transfer Iota

To transfer `1000` MICROS to another address:
To transfer `1000` nano to another address:

```typescript
import { getFullnodeUrl, IotaClient } from '@iota/iota-sdk/client';
Expand Down
Loading

0 comments on commit 21befe0

Please sign in to comment.