1
1
// Copyright 2019-2024 @polkadot/extension-polkagate authors & contributors
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
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 ' ;
7
7
import type { SubmittableExtrinsic } from '@polkadot/api/types/submittable' ;
8
- import type { ISubmittableResult } from '@polkadot/types/types' ;
9
8
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' ;
10
12
11
13
import { Grid , useTheme } from '@mui/material' ;
12
14
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' ;
15
17
import LedgerSign from '../popup/signing/LedgerSign' ;
18
+ import LedgerSignGeneric from '../popup/signing/LedgerSignGeneric' ;
16
19
import { send } from '../util/api' ;
17
20
import { PButton , Warning } from '.' ;
18
- import LedgerSignGeneric from '../popup/signing/LedgerSignGeneric' ;
19
21
20
22
interface Props {
21
23
address : string ;
@@ -26,19 +28,21 @@ interface Props {
26
28
api : ApiPromise | undefined ;
27
29
payload : GenericExtrinsicPayload | undefined ;
28
30
from : string | undefined ;
29
- ptx : SubmittableExtrinsic < " promise" , ISubmittableResult > | undefined ;
31
+ ptx : SubmittableExtrinsic < ' promise' , ISubmittableResult > | undefined ;
30
32
setStep : React . Dispatch < React . SetStateAction < number > > ;
31
33
steps : Record < string , number > ;
32
34
handleTxResult : ( txResult : TxResult ) => void
33
35
}
34
36
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 ) {
36
38
const { t } = useTranslation ( ) ;
37
39
const theme = useTheme ( ) ;
38
- const account = useAccount ( address ) ;
40
+ const { account, chainName } = useInfo ( address ) ;
39
41
40
42
const [ error , setError ] = useState < string | null > ( ) ;
41
43
44
+ const isPolkadotOrItsSystemChains = chainName ?. toLowerCase ( ) ?. includes ( 'polkadot' ) ;
45
+
42
46
const onLedgerGenericSignature = useCallback ( async ( signature : HexString , raw ?: GenericExtrinsicPayload ) => {
43
47
if ( ! api || ! signature || ! ptx || ! from ) {
44
48
return ;
@@ -53,7 +57,7 @@ export default function SignWithLedger({ address, alertText, api, from, handleTx
53
57
const txResult = await send ( from , api , ptx , raw . toHex ( ) , signature ) ;
54
58
55
59
handleTxResult ( txResult ) ;
56
- } , [ api , from , handleTxResult , ptx , setStep , steps [ 'WAIT_SCREEN' ] ] ) ;
60
+ } , [ api , from , handleTxResult , ptx , setStep , steps ] ) ;
57
61
58
62
return (
59
63
< >
@@ -74,22 +78,22 @@ export default function SignWithLedger({ address, alertText, api, from, handleTx
74
78
text = { t ( 'Cancel' ) }
75
79
/>
76
80
</ 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
79
83
? < LedgerSignGeneric
80
- accountIndex = { account ?. accountIndex as number || 0 }
84
+ accountIndex = { account ?. accountIndex || 0 }
81
85
address = { address }
82
- addressOffset = { account ?. addressOffset as number || 0 }
83
- error = { error as string }
86
+ addressOffset = { account ?. addressOffset || 0 }
87
+ error = { error }
84
88
onSignature = { onLedgerGenericSignature }
85
89
payload = { signerPayload }
86
90
setError = { setError }
87
91
showError = { false }
88
92
/>
89
93
: < 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 }
93
97
genesisHash = { account ?. genesisHash || api ?. genesisHash ?. toHex ( ) }
94
98
onSignature = { onSignature }
95
99
payload = { payload }
0 commit comments