File tree Expand file tree Collapse file tree 4 files changed +33
-29
lines changed Expand file tree Collapse file tree 4 files changed +33
-29
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ export interface WalletCheckModule {
33
33
reset ?: ( ) => void
34
34
}
35
35
36
+ export interface Connect {
37
+ ( ) : Promise < { message : string } | string [ ] | undefined >
38
+ }
39
+
36
40
export interface WalletCheckModal {
37
41
heading : string
38
42
description : string
@@ -42,7 +46,7 @@ export interface WalletCheckModal {
42
46
text : string
43
47
}
44
48
eventCode : string
45
- action ?: ( ) => Promise < { message : string } | undefined >
49
+ action ?: Connect | null
46
50
icon ?: string
47
51
}
48
52
@@ -58,7 +62,7 @@ export interface UserState {
58
62
address : string
59
63
network : number
60
64
balance : string
61
- wallet : Wallet | null
65
+ wallet : Wallet
62
66
mobileDevice : boolean
63
67
appNetworkId : number
64
68
}
@@ -127,7 +131,7 @@ export interface Helpers {
127
131
128
132
export interface WalletInterface {
129
133
name : string | undefined
130
- connect ?: ( ) => Promise < { message : string } | string [ ] | undefined >
134
+ connect ?: Connect | null
131
135
disconnect ?: ( ) => void
132
136
address : StateSyncer
133
137
network : StateSyncer
@@ -141,12 +145,12 @@ export interface StateSyncer {
141
145
}
142
146
143
147
export interface Wallet {
144
- name : string
145
- provider : any
146
- type : 'hardware' | 'injected' | 'sdk'
147
- instance ?: any
148
- connect ?: ( ) => Promise < { message : string } | undefined >
149
- dashboard ?: ( ) => void
148
+ name : string | null
149
+ provider : any | null
150
+ type : 'hardware' | 'injected' | 'sdk' | null
151
+ instance ?: any | null
152
+ connect ?: Connect | null
153
+ dashboard ?: ( ) => void | null
150
154
}
151
155
152
156
export interface CommonWalletOptions {
Original file line number Diff line number Diff line change 1
- import { WalletCheckModal , StateAndHelpers } from '../../interfaces'
1
+ import { WalletCheckModal , StateAndHelpers , Connect } from '../../interfaces'
2
2
import { usbIcon } from './icons'
3
3
4
4
interface DerivationPaths {
@@ -189,12 +189,13 @@ function derivationPath(
189
189
wallet . name === 'Ledger' ? 'and the Ethereum app is open, ' : ''
190
190
} then select a derivation path to connect your accounts:`,
191
191
eventCode : 'derivationPath' ,
192
- html : derivationSelectHtmlString ( wallet . name ) ,
192
+ html : derivationSelectHtmlString ( wallet . name as string ) ,
193
193
button : {
194
194
text : 'Connect' ,
195
195
onclick : async ( ) => {
196
196
state . loading = true
197
- const path = state . dPath || derivationPaths [ wallet . name ] [ 0 ] . path
197
+ const path =
198
+ state . dPath || derivationPaths [ wallet . name as string ] [ 0 ] . path
198
199
try {
199
200
const validPath = await wallet . provider . setPath (
200
201
path ,
@@ -214,11 +215,9 @@ function derivationPath(
214
215
215
216
state . error = ''
216
217
217
- wallet . connect &&
218
- wallet
219
- . connect ( )
218
+ if ( wallet . connect ) {
219
+ ; ( wallet . connect as Connect ) ( )
220
220
. then ( ( ) => {
221
- // @TODO add path to local store
222
221
deleteWindowProperties ( )
223
222
state . loading = false
224
223
state . completed = true
@@ -227,6 +226,7 @@ function derivationPath(
227
226
state . error = error . message
228
227
state . loading = false
229
228
} )
229
+ }
230
230
}
231
231
} ,
232
232
Original file line number Diff line number Diff line change @@ -125,11 +125,11 @@ export function resetWalletState(options?: {
125
125
// no options object, so do a full reset by disconnecting and setting interface to null
126
126
if ( ! options ) {
127
127
wallet . update ( ( ) => ( {
128
- name : undefined ,
129
- provider : undefined ,
130
- connect : undefined ,
131
- instance : undefined ,
132
- dashboard : undefined
128
+ name : null ,
129
+ provider : null ,
130
+ connect : null ,
131
+ instance : null ,
132
+ dashboard : null
133
133
} ) )
134
134
135
135
currentInterface . disconnect && currentInterface . disconnect ( )
@@ -142,11 +142,11 @@ export function resetWalletState(options?: {
142
142
// if walletName is the same as the current interface name then do a full reset (checking if to do a disconnect)
143
143
if ( currentInterface . name === walletName ) {
144
144
wallet . update ( ( ) => ( {
145
- name : undefined ,
146
- provider : undefined ,
147
- connect : undefined ,
148
- instance : undefined ,
149
- dashboard : undefined
145
+ name : null ,
146
+ provider : null ,
147
+ connect : null ,
148
+ instance : null ,
149
+ dashboard : null
150
150
} ) )
151
151
152
152
! disconnected &&
Original file line number Diff line number Diff line change 28
28
WalletSelectFunction ,
29
29
AppState ,
30
30
WalletCheckModal ,
31
- UserState
31
+ UserState ,
32
+ Connect
32
33
} from ' ../interfaces'
33
34
34
35
export let walletSelect: WalletSelectFunction
155
156
156
157
activeModal &&
157
158
activeModal .action &&
158
- activeModal
159
- .action ()
159
+ (activeModal .action as Connect )()
160
160
.then (() => {
161
161
actionResolved = true
162
162
loading = false
You can’t perform that action at this time.
0 commit comments