Skip to content

Commit

Permalink
Merge branch 'develop' into dev-tools/remove-MultiSigCombinePartialSi…
Browse files Browse the repository at this point in the history
…gLegacy
  • Loading branch information
thibault-martinez authored Aug 13, 2024
2 parents aedd425 + 2d52a43 commit e794e70
Show file tree
Hide file tree
Showing 46 changed files with 432 additions and 385 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ export function ImportPrivateKeyForm({ onSubmit }: ImportPrivateKeyFormProps) {
const isHexadecimal = isValid && !privateKey.startsWith('iotaprivkey');
return (
<Form className="flex h-full flex-col gap-2" form={form} onSubmit={onSubmit}>
<TextAreaField label="Enter Private Key" rows={4} {...register('privateKey')} />
<TextAreaField
label="Enter Private Key"
rows={4}
{...register('privateKey')}
errorMessage={form.formState.errors.privateKey?.message}
/>
{isHexadecimal ? (
<InfoBox
type={InfoBoxType.Default}
Expand Down
34 changes: 23 additions & 11 deletions apps/wallet/src/ui/app/components/accounts/ImportSeedForm.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { Button } from '_app/shared/ButtonUI';
import { useZodForm } from '@iota/core';
import { type SubmitHandler } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
import { z } from 'zod';

import { seedValidation } from '../../helpers/validation/seedValidation';
import { Form } from '../../shared/forms/Form';
import { Button, ButtonType, ButtonHtmlType } from '@iota/apps-ui-kit';
import { TextAreaField } from '../../shared/forms/TextAreaField';

const formSchema = z.object({
Expand All @@ -33,17 +32,30 @@ export function ImportSeedForm({ onSubmit }: ImportSeedFormProps) {
const navigate = useNavigate();

return (
<Form className="flex h-full flex-col gap-2" form={form} onSubmit={onSubmit}>
<TextAreaField label="Enter Seed" rows={5} {...register('seed')} />
<div className="mt-auto flex gap-2.5">
<Button variant="outline" size="tall" text="Cancel" onClick={() => navigate(-1)} />
<Form
className="flex h-full flex-col justify-between gap-2"
form={form}
onSubmit={onSubmit}
>
<TextAreaField
label="Enter Seed"
rows={5}
{...register('seed')}
errorMessage={form.formState.errors.seed?.message}
/>
<div className="flex flex-row justify-stretch gap-2.5">
<Button
type={ButtonType.Secondary}
text="Cancel"
onClick={() => navigate(-1)}
fullWidth
/>
<Button
type="submit"
type={ButtonType.Primary}
disabled={isSubmitting || !isValid}
variant="primary"
size="tall"
loading={isSubmitting}
text="Add Account"
text="Add Profile"
fullWidth
htmlType={ButtonHtmlType.Submit}
/>
</div>
</Form>
Expand Down
26 changes: 13 additions & 13 deletions apps/wallet/src/ui/app/pages/accounts/ImportPassphrasePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ export function ImportPassphrasePage() {
setIsTextVisible(!isTextVisible);
}

function handleOnSubmit({ recoveryPhrase }: { recoveryPhrase: string[] }) {
setFormValues({
type: AccountsFormType.ImportMnemonic,
entropy: entropyToSerialized(mnemonicToEntropy(recoveryPhrase.join(' '))),
});
navigate(
`/accounts/protect-account?${new URLSearchParams({
accountsFormType: AccountsFormType.ImportMnemonic,
}).toString()}`,
);
}

const BUTTON_ICON_CLASSES = 'w-5 h-5 text-neutral-10';
return (
<PageTemplate title="Import Mnemonic" isTitleCentered showBackButton>
Expand All @@ -47,19 +59,7 @@ export function ImportPassphrasePage() {
cancelButtonText="Back"
submitButtonText="Add Profile"
isTextVisible={isTextVisible}
onSubmit={({ recoveryPhrase }) => {
setFormValues({
type: AccountsFormType.ImportMnemonic,
entropy: entropyToSerialized(
mnemonicToEntropy(recoveryPhrase.join(' ')),
),
});
navigate(
`/accounts/protect-account?${new URLSearchParams({
accountsFormType: AccountsFormType.ImportMnemonic,
}).toString()}`,
);
}}
onSubmit={handleOnSubmit}
/>
</div>
</div>
Expand Down
26 changes: 13 additions & 13 deletions apps/wallet/src/ui/app/pages/accounts/ImportPrivateKeyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ export function ImportPrivateKeyPage() {
const navigate = useNavigate();
const [, setAccountsFormValues] = useAccountsFormContext();

function handleOnSubmit({ privateKey }: { privateKey: string }) {
setAccountsFormValues({
type: AccountsFormType.ImportPrivateKey,
keyPair: privateKey,
});
navigate(
`/accounts/protect-account?${new URLSearchParams({
accountsFormType: AccountsFormType.ImportPrivateKey,
}).toString()}`,
);
}

return (
<PageTemplate title="Import Private Key" isTitleCentered showBackButton>
<div className="flex h-full w-full flex-col items-center ">
<div className="w-full grow">
<ImportPrivateKeyForm
onSubmit={({ privateKey }) => {
setAccountsFormValues({
type: AccountsFormType.ImportPrivateKey,
keyPair: privateKey,
});
navigate(
`/accounts/protect-account?${new URLSearchParams({
accountsFormType: AccountsFormType.ImportPrivateKey,
}).toString()}`,
);
}}
/>
<ImportPrivateKeyForm onSubmit={handleOnSubmit} />
</div>
</div>
</PageTemplate>
Expand Down
46 changes: 19 additions & 27 deletions apps/wallet/src/ui/app/pages/accounts/ImportSeedPage.tsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { Text } from '_app/shared/text';
import { useNavigate } from 'react-router-dom';

import {
AccountsFormType,
useAccountsFormContext,
} from '../../components/accounts/AccountsFormContext';
import { ImportSeedForm } from '../../components/accounts/ImportSeedForm';
import { Heading } from '../../shared/heading';
import { PageTemplate } from '../../components/PageTemplate';

export function ImportSeedPage() {
const navigate = useNavigate();
const [, setAccountsFormValues] = useAccountsFormContext();

function handleOnSubmit({ seed }: { seed: string }) {
setAccountsFormValues({
type: AccountsFormType.ImportSeed,
seed,
});
navigate(
`/accounts/protect-account?${new URLSearchParams({
accountsFormType: AccountsFormType.ImportSeed,
}).toString()}`,
);
}

return (
<div className="bg-iota-lightest flex h-full w-full flex-col items-center rounded-20 px-6 py-10 shadow-wallet-content">
<Text variant="caption" color="steel-dark" weight="semibold">
Wallet Setup
</Text>
<div className="mt-2.5 text-center">
<Heading variant="heading1" color="gray-90" as="h1" weight="bold">
Import Seed
</Heading>
</div>
<div className="mt-6 w-full grow">
<ImportSeedForm
onSubmit={({ seed }) => {
setAccountsFormValues({
type: AccountsFormType.ImportSeed,
seed,
});
navigate(
`/accounts/protect-account?${new URLSearchParams({
accountsFormType: AccountsFormType.ImportSeed,
}).toString()}`,
);
}}
/>
<PageTemplate title="Import Seed" isTitleCentered showBackButton>
<div className="flex h-full w-full flex-col items-center ">
<div className="w-full grow">
<ImportSeedForm onSubmit={handleOnSubmit} />
</div>
</div>
</div>
</PageTemplate>
);
}
5 changes: 4 additions & 1 deletion apps/wallet/src/ui/app/pages/accounts/WelcomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function WelcomePage() {
!(createAccountsMutation.isPending || createAccountsMutation.isSuccess),
);
const navigate = useNavigate();
const CURRENT_YEAR = new Date().getFullYear();

return (
<Loading loading={isInitializedLoading || isFullscreenGuardLoading}>
Expand All @@ -42,7 +43,9 @@ export function WelcomePage() {
}
/>
</div>
<div className="text-body-lg text-neutral-60">&copy; IOTA Foundation 2024</div>
<div className="text-body-lg text-neutral-60">
&copy; IOTA Foundation {CURRENT_YEAR}
</div>
</div>
</Loading>
);
Expand Down
Loading

0 comments on commit e794e70

Please sign in to comment.