mirror of
https://github.com/pezkuwichain/pezkuwi-extension.git
synced 2026-04-22 03:17:58 +00:00
5d54192e6d
- Update all copyright headers from 2025 to 2026 - Fix @polkadot references to @pezkuwi in config files - Fix eslint.config.js import path Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
105 lines
2.8 KiB
TypeScript
105 lines
2.8 KiB
TypeScript
// Copyright 2019-2026 @pezkuwi/extension-ui authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { HexString } from '@pezkuwi/util/types';
|
|
|
|
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
|
|
|
import AccountNamePasswordCreation from '../../components/AccountNamePasswordCreation.js';
|
|
import { AccountContext, ActionContext, Address } from '../../components/index.js';
|
|
import { useMetadata, useTranslation } from '../../hooks/index.js';
|
|
import { createAccountSuri } from '../../messaging.js';
|
|
import { HeaderWithSteps } from '../../partials/index.js';
|
|
import { DEFAULT_TYPE } from '../../util/defaultType.js';
|
|
import SeedAndPath from './SeedAndPath.js';
|
|
|
|
export interface AccountInfo {
|
|
address: string;
|
|
genesis?: HexString;
|
|
suri: string;
|
|
}
|
|
|
|
function ImportSeed (): React.ReactElement {
|
|
const { t } = useTranslation();
|
|
const { accounts } = useContext(AccountContext);
|
|
const onAction = useContext(ActionContext);
|
|
const [isBusy, setIsBusy] = useState(false);
|
|
const [account, setAccount] = useState<AccountInfo | null>(null);
|
|
const [name, setName] = useState<string | null>(null);
|
|
const [step1, setStep1] = useState(true);
|
|
const [type, setType] = useState(DEFAULT_TYPE);
|
|
const chain = useMetadata(account?.genesis, true);
|
|
|
|
useEffect((): void => {
|
|
!accounts.length && onAction();
|
|
}, [accounts, onAction]);
|
|
|
|
useEffect((): void => {
|
|
setType(
|
|
chain && chain.definition.chainType === 'ethereum'
|
|
? 'ethereum'
|
|
: DEFAULT_TYPE
|
|
);
|
|
}, [chain]);
|
|
|
|
const _onCreate = useCallback((name: string, password: string): void => {
|
|
// this should always be the case
|
|
if (name && password && account) {
|
|
setIsBusy(true);
|
|
|
|
createAccountSuri(name, password, account.suri, type, account.genesis)
|
|
.then(() => onAction('/'))
|
|
.catch((error): void => {
|
|
setIsBusy(false);
|
|
console.error(error);
|
|
});
|
|
}
|
|
}, [account, onAction, type]);
|
|
|
|
const _onNextStep = useCallback(
|
|
() => setStep1(false),
|
|
[]
|
|
);
|
|
|
|
const _onBackClick = useCallback(
|
|
() => setStep1(true),
|
|
[]
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<HeaderWithSteps
|
|
step={step1 ? 1 : 2}
|
|
text={t('Import account')}
|
|
/>
|
|
<div>
|
|
<Address
|
|
address={account?.address}
|
|
genesisHash={account?.genesis}
|
|
name={name}
|
|
/>
|
|
</div>
|
|
{step1
|
|
? (
|
|
<SeedAndPath
|
|
onAccountChange={setAccount}
|
|
onNextStep={_onNextStep}
|
|
type={type}
|
|
/>
|
|
)
|
|
: (
|
|
<AccountNamePasswordCreation
|
|
buttonLabel={t('Add the account with the supplied seed')}
|
|
isBusy={isBusy}
|
|
onBackClick={_onBackClick}
|
|
onCreate={_onCreate}
|
|
onNameChange={setName}
|
|
/>
|
|
)
|
|
}
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default ImportSeed;
|