Skip to content

Commit 14c4350

Browse files
committed
init
1 parent 51805b2 commit 14c4350

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

packages/extension-polkagate/src/components/SignWithLedger.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import type { SignerPayloadJSON } from '@polkadot/types/types';
5-
import type { HexString } from '@polkadot/util/types';
6-
import type { TxResult } from '../util/types';
4+
/* eslint-disable react/jsx-max-props-per-line */
5+
6+
import type { ApiPromise } from '@polkadot/api';
77
import type { SubmittableExtrinsic } from '@polkadot/api/types/submittable';
8-
import type { ISubmittableResult } from '@polkadot/types/types';
98
import type { GenericExtrinsicPayload } from '@polkadot/types';
9+
import type { ISubmittableResult, SignerPayloadJSON } from '@polkadot/types/types';
10+
import type { HexString } from '@polkadot/util/types';
11+
import type { TxResult } from '../util/types';
1012

1113
import { Grid, useTheme } from '@mui/material';
1214
import React, { useCallback, useState } from 'react';
13-
import { ApiPromise } from '@polkadot/api';
14-
import { useAccount, useTranslation } from '../hooks';
15+
16+
import { useInfo, useTranslation } from '../hooks';
1517
import LedgerSign from '../popup/signing/LedgerSign';
18+
import LedgerSignGeneric from '../popup/signing/LedgerSignGeneric';
1619
import { send } from '../util/api';
1720
import { PButton, Warning } from '.';
18-
import LedgerSignGeneric from '../popup/signing/LedgerSignGeneric';
1921

2022
interface Props {
2123
address: string;
@@ -26,19 +28,21 @@ interface Props {
2628
api: ApiPromise | undefined;
2729
payload: GenericExtrinsicPayload | undefined;
2830
from: string | undefined;
29-
ptx: SubmittableExtrinsic<"promise", ISubmittableResult> | undefined;
31+
ptx: SubmittableExtrinsic<'promise', ISubmittableResult> | undefined;
3032
setStep: React.Dispatch<React.SetStateAction<number>>;
3133
steps: Record<string, number>;
3234
handleTxResult: (txResult: TxResult) => void
3335
}
3436

35-
export default function SignWithLedger({ address, alertText, api, from, handleTxResult, onSecondaryClick, signerPayload, onSignature, payload, ptx, setStep, steps }: Props) {
37+
export default function SignWithLedger ({ address, alertText, api, from, handleTxResult, onSecondaryClick, onSignature, payload, ptx, setStep, signerPayload, steps }: Props) {
3638
const { t } = useTranslation();
3739
const theme = useTheme();
38-
const account = useAccount(address);
40+
const { account, chainName } = useInfo(address);
3941

4042
const [error, setError] = useState<string | null>();
4143

44+
const isPolkadotOrItsSystemChains = chainName?.toLowerCase()?.includes('polkadot');
45+
4246
const onLedgerGenericSignature = useCallback(async (signature: HexString, raw?: GenericExtrinsicPayload) => {
4347
if (!api || !signature || !ptx || !from) {
4448
return;
@@ -53,7 +57,7 @@ export default function SignWithLedger({ address, alertText, api, from, handleTx
5357
const txResult = await send(from, api, ptx, raw.toHex(), signature);
5458

5559
handleTxResult(txResult);
56-
}, [api, from, handleTxResult, ptx, setStep, steps['WAIT_SCREEN']]);
60+
}, [api, from, handleTxResult, ptx, setStep, steps]);
5761

5862
return (
5963
<>
@@ -74,22 +78,22 @@ export default function SignWithLedger({ address, alertText, api, from, handleTx
7478
text={t('Cancel')}
7579
/>
7680
</Grid>
77-
<Grid item sx={{ 'button': { m: 0, width: '100%' }, mt: '80px', position: 'relative', width: '70%' }} xs={8}>
78-
{account?.isGeneric || account?.isMigration
81+
<Grid item sx={{ button: { m: 0, width: '100%' }, mt: '80px', position: 'relative', width: '70%' }} xs={8}>
82+
{account?.isGeneric || account?.isMigration || isPolkadotOrItsSystemChains
7983
? <LedgerSignGeneric
80-
accountIndex={account?.accountIndex as number || 0}
84+
accountIndex={account?.accountIndex || 0}
8185
address={address}
82-
addressOffset={account?.addressOffset as number || 0}
83-
error={error as string}
86+
addressOffset={account?.addressOffset || 0}
87+
error={error}
8488
onSignature={onLedgerGenericSignature}
8589
payload={signerPayload}
8690
setError={setError}
8791
showError={false}
8892
/>
8993
: <LedgerSign
90-
accountIndex={account?.accountIndex as number || 0}
91-
addressOffset={account?.addressOffset as number || 0}
92-
error={error as string}
94+
accountIndex={account?.accountIndex || 0}
95+
addressOffset={account?.addressOffset || 0}
96+
error={error}
9397
genesisHash={account?.genesisHash || api?.genesisHash?.toHex()}
9498
onSignature={onSignature}
9599
payload={payload}

packages/extension-polkagate/src/popup/signing/LedgerSign.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface Props {
1818
accountIndex?: number;
1919
addressOffset?: number;
2020
className?: string;
21-
error: string | null;
21+
error: string | null | undefined;
2222
genesisHash?: string;
2323
onSignature?: ({ signature }: { signature: HexString }) => void;
2424
payload?: ExtrinsicPayload;

packages/extension-polkagate/src/popup/signing/LedgerSignGeneric.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,47 @@
33

44
/* eslint-disable react/jsx-max-props-per-line */
55

6+
import type { LedgerSignature } from '@polkadot/hw-ledger/types';
7+
import type { GenericExtrinsicPayload } from '@polkadot/types';
8+
import type { SignerPayloadJSON } from '@polkadot/types/types';
69
import type { HexString } from '@polkadot/util/types';
10+
711
import { Grid, useTheme } from '@mui/material';
8-
import React, { useCallback, useEffect, useState, useMemo } from 'react';
12+
import React, { useCallback, useEffect, useMemo,useState } from 'react';
913
import styled from 'styled-components';
14+
1015
import { PButton, Warning } from '../../components';
11-
import useTranslation from '../../hooks/useTranslation';
1216
import { useGenericLedger, useInfo, useMetadataProof } from '../../hooks';
17+
import useTranslation from '../../hooks/useTranslation';
1318
import ledgerChains from '../../util/legerChains';
14-
import type { SignerPayloadJSON } from '@polkadot/types/types';
15-
import type { LedgerSignature } from '@polkadot/hw-ledger/types';
16-
import type { GenericExtrinsicPayload } from '@polkadot/types';
1719

1820
interface Props {
1921
accountIndex?: number;
2022
address: string | undefined;
2123
addressOffset?: number;
2224
className?: string;
23-
error: string | null;
25+
error: string | null | undefined;
2426
onSignature?: (signature: HexString, raw?: GenericExtrinsicPayload) => void;
2527
payload?: SignerPayloadJSON;
2628
setError: (value: string | null) => void;
2729
showError?: boolean;
2830
}
2931

30-
function LedgerSignGeneric({ accountIndex, address, addressOffset, error, onSignature, payload, setError, showError = true }: Props): React.ReactElement<Props> {
32+
function LedgerSignGeneric ({ accountIndex, address, addressOffset, error, onSignature, payload, setError, showError = true }: Props): React.ReactElement<Props> {
3133
const { t } = useTranslation();
3234
const theme = useTheme();
33-
const { api, account } = useInfo(address);
35+
const { account, api } = useInfo(address);
3436
const metadataProof = useMetadataProof(api, payload);
3537

3638
const [isBusy, setIsBusy] = useState<boolean>(false);
3739

3840
const chainSlip44 = useMemo(() => {
3941
if (account?.genesisHash) {
40-
return ledgerChains.find(({ genesisHash }) => genesisHash.includes(account.genesisHash as any))?.slip44 ?? null
42+
return ledgerChains.find(({ genesisHash }) => genesisHash.includes(account.genesisHash as HexString))?.slip44 ?? null;
4143
}
44+
4245
return null;
43-
}, [account, ledgerChains]);
46+
}, [account]);
4447

4548
const { error: ledgerError, isLoading: ledgerLoading, isLocked: ledgerLocked, ledger, refresh, warning: ledgerWarning } = useGenericLedger(accountIndex, addressOffset, chainSlip44);
4649

0 commit comments

Comments
 (0)