@@ -30,7 +30,7 @@ const baseStyles = `
30
30
border-radius: 40px;
31
31
margin-top: 0.5rem;
32
32
padding: 0.55em 1.4em;
33
- cursor: pointer ;
33
+ text-align: center ;
34
34
color: inherit;
35
35
font-family: inherit;
36
36
transition: background 150ms ease-in-out;
@@ -49,22 +49,17 @@ const errorStyles = `
49
49
border: 1px solid #e2504a;
50
50
`
51
51
52
- const errorMsgStyles = `
52
+ const msgStyles = `
53
+ display: block;
53
54
font-size: 0.889em;
54
55
font-family: inherit;
55
- color: #e2504a;
56
+ color: inherit;
57
+ margin-top: 0.5rem;
56
58
`
57
59
58
- const customInputHtmlString = ( error ?: string ) => {
59
- return `
60
- <input
61
- id="custom-derivation-input"
62
- style="${ baseStyles + selectedStyles + ( error ? errorStyles : '' ) } "
63
- type="text"
64
- placeholder="custom derivation path"
65
- onchange="window.handleCustomInput(this.value)" />
66
- `
67
- }
60
+ const errorMsgStyles = `
61
+ color: #e2504a;
62
+ `
68
63
69
64
function derivationPath ( options : {
70
65
heading : string
@@ -81,6 +76,18 @@ function derivationPath(options: {
81
76
error : ''
82
77
}
83
78
79
+ const customInputHtmlString = ( error ?: string ) => {
80
+ return `
81
+ <input
82
+ id="custom-derivation-input"
83
+ style="${ baseStyles + selectedStyles + ( error ? errorStyles : '' ) } "
84
+ type="text"
85
+ value="${ state . dPath } "
86
+ placeholder="custom derivation path"
87
+ onchange="window.handleCustomInput(this.value)" />
88
+ `
89
+ }
90
+
84
91
function derivationSelectHtmlString ( walletName : string ) {
85
92
return `
86
93
<div id="derivation-select" style="${ styles } ">
@@ -90,7 +97,7 @@ function derivationPath(options: {
90
97
return `
91
98
<button style="${ baseStyles +
92
99
buttonStyles +
93
- ( state . dPath === path
100
+ ( state . dPath === path && ! state . showCustomInput
94
101
? selectedStyles
95
102
: '' ) } " onclick="window.handleDerivationClick(this)" data-path="${ path } ">
96
103
${ label } - ${ path }
@@ -106,13 +113,17 @@ function derivationPath(options: {
106
113
}
107
114
${
108
115
state . loading
109
- ? `<div class="bn-onboard-custom bn-onboard-loading" style="margin-top: 1rem">
116
+ ? `<div class="bn-onboard-custom bn-onboard-loading" style="margin-top: 1rem; ">
110
117
<div class="bn-onboard-loading-first"></div>
111
118
<div class="bn-onboard-loading-second"></div>
112
- <div class="bn-onboard-loading-third"</div>
113
- </div>`
119
+ <div class="bn-onboard-loading-third"></div>
120
+ </div>
121
+ <span style="${ msgStyles } ">Loading Accounts...</span>
122
+ `
114
123
: state . error
115
- ? `<span style="${ errorMsgStyles } ">${ state . error } </span>`
124
+ ? `<span style="${ msgStyles + errorMsgStyles } ">${
125
+ state . error
126
+ } </span>`
116
127
: ''
117
128
}
118
129
</div>
@@ -147,7 +158,7 @@ function derivationPath(options: {
147
158
148
159
if ( selectedPath === 'custom' ) {
149
160
state . showCustomInput = true
150
- state . dPath = ''
161
+
151
162
setTimeout ( ( ) => {
152
163
const input = document . getElementById ( 'custom-derivation-input' )
153
164
input && input . focus ( )
@@ -170,35 +181,48 @@ function derivationPath(options: {
170
181
heading : heading || 'Hardware Wallet Connect' ,
171
182
description :
172
183
description ||
173
- `Please select a derivation path to connect your ${ wallet . name } accounts, or select custom to input a custom path:` ,
184
+ `Make sure your ${ wallet . name } is plugged in, ${
185
+ wallet . name === 'Ledger' ? 'and the Ethereum app is open, ' : ''
186
+ } then select a derivation path to connect your accounts:`,
174
187
eventCode : 'derivationPath' ,
175
188
html : derivationSelectHtmlString ( wallet . name ) ,
176
189
button : {
177
190
text : 'Connect' ,
178
191
onclick : async ( ) => {
179
192
state . loading = true
180
193
const path = state . dPath || derivationPaths [ wallet . name ] [ 0 ] . path
181
- const validPath = await wallet . provider . setPath (
182
- path ,
183
- state . showCustomInput
184
- )
185
-
186
- if ( ! validPath ) {
187
- state . error = `${ path } is not a valid derivation path`
194
+ try {
195
+ const validPath = await wallet . provider . setPath (
196
+ path ,
197
+ state . showCustomInput
198
+ )
199
+
200
+ if ( ! validPath ) {
201
+ state . error = `${ path } is not a valid derivation path`
202
+ state . loading = false
203
+ return
204
+ }
205
+ } catch ( error ) {
206
+ state . error = error
188
207
state . loading = false
189
208
return
190
209
}
191
210
192
211
state . error = ''
193
212
194
213
wallet . connect &&
195
- wallet . connect ( ) . then ( ( ) => {
196
- // @TODO add path to local store
197
-
198
- deleteWindowProperties ( )
199
- state . loading = false
200
- state . completed = true
201
- } )
214
+ wallet
215
+ . connect ( )
216
+ . then ( ( ) => {
217
+ // @TODO add path to local store
218
+ deleteWindowProperties ( )
219
+ state . loading = false
220
+ state . completed = true
221
+ } )
222
+ . catch ( error => {
223
+ state . error = error . message
224
+ state . loading = false
225
+ } )
202
226
}
203
227
} ,
204
228
0 commit comments