1
- import { WalletCheckModule , StateAndHelpers } from '../../interfaces'
1
+ import {
2
+ WalletCheckModule ,
3
+ StateAndHelpers ,
4
+ WalletCheckModal
5
+ } from '../../interfaces'
6
+ import { usbIcon } from './icons'
2
7
3
8
type AccountsAndBalances = Array < { balance : string ; address : string } >
4
9
5
- function accountSelect ( ) : WalletCheckModule | never {
10
+ const msgStyles = `
11
+ display: block;
12
+ font-size: 0.889em;
13
+ font-family: inherit;
14
+ color: inherit;
15
+ margin-top: 0.5rem;
16
+ `
17
+
18
+ function accountSelect (
19
+ options : {
20
+ heading ?: string
21
+ description ?: string
22
+ icon ?: string
23
+ } = { }
24
+ ) : WalletCheckModule {
25
+ const { heading, description, icon } = options
6
26
let completed : boolean = false
7
27
let loadingAccounts : boolean = false
8
28
let accountsAndBalances : AccountsAndBalances = [ ]
9
29
10
- return async ( stateAndHelpers : StateAndHelpers ) => {
11
- const { wallet, BigNumber, address, balance } = stateAndHelpers
30
+ async function checkModule (
31
+ stateAndHelpers : StateAndHelpers
32
+ ) : Promise < WalletCheckModal | undefined > {
33
+ const { wallet, BigNumber } = stateAndHelpers
12
34
const { provider, type } = wallet
13
35
14
- if ( type === 'hardware' && ! completed ) {
15
- if ( accountsAndBalances . length <= 1 && ! loadingAccounts ) {
16
- accountsAndBalances = [ { address, balance } ]
36
+ if ( type === 'hardware' && ! completed && ! provider . isCustomPath ( ) ) {
37
+ if ( accountsAndBalances . length === 0 ) {
38
+ loadingAccounts = true
39
+ const accounts = await provider . enable ( )
40
+ accountsAndBalances = await provider . getBalances ( accounts )
41
+ loadingAccounts = false
17
42
}
18
43
19
44
const deleteWindowProperties = ( ) => {
@@ -23,8 +48,7 @@ function accountSelect(): WalletCheckModule | never {
23
48
24
49
const loadMoreAccounts = async ( ) => {
25
50
loadingAccounts = true
26
- const moreAccounts = await provider . getAllAccountsAndBalances ( )
27
- accountsAndBalances = moreAccounts
51
+ accountsAndBalances = await provider . getMoreAccounts ( )
28
52
loadingAccounts = false
29
53
}
30
54
@@ -38,28 +62,35 @@ function accountSelect(): WalletCheckModule | never {
38
62
; ( window as any ) . loadMoreAccounts = loadMoreAccounts
39
63
40
64
return {
41
- heading : 'Select Account' ,
42
- description : `Please select which account you would like to use with this Dapp:` ,
65
+ heading : heading || 'Select Account' ,
66
+ description :
67
+ description ||
68
+ `Please select which account you would like to use with this Dapp:` ,
43
69
eventCode : 'accountSelect' ,
44
70
html : loadingAccounts
45
71
? `<div class="bn-onboard-custom bn-onboard-loading">
46
72
<div class="bn-onboard-loading-first"></div>
47
73
<div class="bn-onboard-loading-second"></div>
48
- <div class="bn-onboard-loading-third"</div>
49
- </div>`
74
+ <div class="bn-onboard-loading-third"></div>
75
+ </div>
76
+ <span style="${ msgStyles } ">Loading More Accounts...</span>
77
+ `
50
78
: `
51
- <select id="account-select" onchange="window.accountSelect()" style="padding: 0.5rem;">
52
- ${ accountsAndBalances . map (
53
- ( account : { balance : string ; address : string } ) =>
54
- `<option value="${ account . address } ">${ account . address } --- ${
55
- account . balance != null
56
- ? new BigNumber ( account . balance )
57
- . div ( '1000000000000000000' )
58
- . toFixed ( 3 )
59
- : '0'
60
- } ETH</option>`
61
- ) }
62
- </select><button style="background: transparent; margin: 0 0.25rem; padding: 0.25rem 0.5rem; border-radius: 40px; cursor: pointer; color: inherit; border-color: inherit; border-width: 1px;" onclick="window.loadMoreAccounts()">Load More</button>
79
+ <div style="display: flex; align-items: center;">
80
+ <select id="account-select" onchange="window.accountSelect()" style="padding: 0.5rem;">
81
+ ${ accountsAndBalances . map (
82
+ ( account : { balance : string ; address : string } ) =>
83
+ `<option>${ account . address } --- ${
84
+ account . balance != null
85
+ ? new BigNumber ( account . balance )
86
+ . div ( '1000000000000000000' )
87
+ . toFixed ( 3 )
88
+ : '0'
89
+ } ETH</option>`
90
+ ) }
91
+ </select>
92
+ <button style="display: flex; align-items: center; text-align: center; height: 1.5rem; background: transparent; margin: 0 0.25rem; padding: 0 0.5rem; border-radius: 40px; cursor: pointer; color: inherit; border-color: inherit; border-width: 1px; border-style: solid;" onclick="window.loadMoreAccounts()">Load More</button>
93
+ </div>
63
94
` ,
64
95
button : {
65
96
onclick : ( ) => {
@@ -68,12 +99,18 @@ function accountSelect(): WalletCheckModule | never {
68
99
} ,
69
100
text : 'Done'
70
101
} ,
71
- icon : `
72
- <svg height="18" viewBox="0 0 18 18" width="18" xmlns="http://www.w3.org/2000/svg"><path d="m13.375 28c-1.86075 0-3.375-1.51425-3.375-3.375s1.51425-3.375 3.375-3.375 3.375 1.51425 3.375 3.375-1.51425 3.375-3.375 3.375zm0-4.5c-.619875 0-1.125.504-1.125 1.125s.505125 1.125 1.125 1.125 1.125-.504 1.125-1.125-.505125-1.125-1.125-1.125zm0-6.75c-1.86075 0-3.375-1.51425-3.375-3.375s1.51425-3.375 3.375-3.375 3.375 1.51425 3.375 3.375-1.51425 3.375-3.375 3.375zm0-4.5c-.619875 0-1.125.505125-1.125 1.125s.505125 1.125 1.125 1.125 1.125-.505125 1.125-1.125-.505125-1.125-1.125-1.125zm11.25 4.5c-1.86075 0-3.375-1.51425-3.375-3.375s1.51425-3.375 3.375-3.375 3.375 1.51425 3.375 3.375-1.51425 3.375-3.375 3.375zm0-4.5c-.621 0-1.125.505125-1.125 1.125s.504 1.125 1.125 1.125 1.125-.505125 1.125-1.125-.504-1.125-1.125-1.125zm-11.25 10.117125h-.014625c-.615375-.007875-1.110375-.50175-1.110375-1.117125 0-1.35675.898875-3.375 3.375-3.375h6.75c.50625-.0135 1.125-.219375 1.125-1.125v-1.125c0-.621.502875-1.125 1.125-1.125s1.125.504 1.125 1.125v1.125c0 2.476125-2.01825 3.375-3.375 3.375h-6.75c-.905625 0-1.1115.61875-1.125 1.1385-.01575.610875-.51525 1.103625-1.125 1.103625zm0 1.132875c-.621 0-1.125-.502875-1.125-1.125v-6.75c0-.621.504-1.125 1.125-1.125s1.125.504 1.125 1.125v6.75c0 .622125-.504 1.125-1.125 1.125z" fill="currentColor" transform="translate(-10 -10)"/></svg>
73
- `
102
+ icon : icon || usbIcon
74
103
}
75
104
}
76
105
}
106
+
107
+ checkModule . reset = ( ) => {
108
+ completed = false
109
+ accountsAndBalances = [ ]
110
+ loadingAccounts = false
111
+ }
112
+
113
+ return checkModule
77
114
}
78
115
79
116
export default accountSelect
0 commit comments