Skip to content

Commit cb047ec

Browse files
authored
Merge pull request #355 from blocknative/develop
Release 1.9.1
2 parents 5f3222a + aa8287e commit cb047ec

File tree

10 files changed

+169
-93
lines changed

10 files changed

+169
-93
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.9.0",
3+
"version": "1.9.1",
44
"description": "Onboard users to web3 by allowing them to select a wallet, get that wallet ready to transact and have access to synced wallet state.",
55
"keywords": [
66
"ethereum",

src/components/Modal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
div {
5353
height: 0.66em;
5454
position: absolute;
55-
padding: 0.8em;
55+
padding: 0.25em;
5656
top: 1.33em;
5757
right: 1.33em;
5858
font-size: inherit;

src/elements/Button.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { app } from '../stores'
33
export let onclick: () => void = () => {}
4+
export let position: string
45
</script>
56

67
<style>
@@ -24,11 +25,22 @@
2425
button:hover {
2526
background: #ecf3fc;
2627
}
28+
29+
.bn-onboard-prepare-button-right {
30+
position: absolute;
31+
right: 0;
32+
}
33+
34+
.bn-onboard-prepare-button-left {
35+
position: absolute;
36+
left: 0;
37+
}
2738
</style>
2839

2940
<button
3041
on:click={onclick}
31-
class="bn-onboard-custom bn-onboard-button"
42+
class:bn-onboard-prepare-button-right={position === 'right'}
43+
class:bn-onboard-prepare-button-left={position === 'left'}
3244
class:bn-onboard-dark-mode-link={$app.darkMode}
3345
class:bn-onboard-dark-mode-background-hover={$app.darkMode}>
3446
<slot />

src/interfaces.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,20 @@ export type AllWalletInitOptions = CommonWalletOptions &
249249
ImTokenOptions &
250250
TrustWalletOptions & { networkId: number }
251251

252-
export interface WalletCheckInit {
253-
checkName: string
252+
export interface WalletCheckCustomOptions {
253+
heading?: string
254+
description?: string
254255
minimumBalance?: string
256+
icon?: string
257+
button?: {
258+
text: string
259+
onclick: () => void
260+
}
261+
html?: string
262+
}
263+
264+
export interface WalletCheckInit extends WalletCheckCustomOptions {
265+
checkName: string
255266
}
256267

257268
export interface WalletSelectFunction {

src/modules/check/balance.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
import { WalletCheckModal, StateAndHelpers } from '../../interfaces'
2-
import { validateType } from '../../validation'
1+
import {
2+
WalletCheckModal,
3+
StateAndHelpers,
4+
WalletCheckCustomOptions
5+
} from '../../interfaces'
36
import { balanceIcon } from './icons'
47

58
function balance(
6-
options: {
7-
minimumBalance: string
8-
heading?: string
9-
description?: string
10-
icon?: string
11-
} = { minimumBalance: '0' }
9+
options: WalletCheckCustomOptions & { minimumBalance: string } = {
10+
minimumBalance: '0'
11+
}
1212
): (currentState: StateAndHelpers) => Promise<WalletCheckModal | undefined> {
13-
validateType({ name: 'balance options', value: options, type: 'object' })
14-
15-
const { minimumBalance, heading, description, icon } = options
16-
17-
validateType({
18-
name: 'minimumBalance',
19-
value: minimumBalance,
20-
type: 'string'
21-
})
13+
const { minimumBalance, heading, description, icon, html, button } = options
2214

2315
return async (StateAndHelpers: StateAndHelpers) => {
2416
const { balance, BigNumber, stateSyncStatus, stateStore } = StateAndHelpers
@@ -44,7 +36,9 @@ function balance(
4436
.div(BigNumber('1000000000000000000'))
4537
.toString(10)} ETH.`,
4638
eventCode: 'nsfFail',
47-
icon: icon || balanceIcon
39+
icon: icon || balanceIcon,
40+
html,
41+
button
4842
}
4943
}
5044
}

src/modules/check/connect.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import {
22
WalletCheckModal,
33
StateAndHelpers,
4-
WalletCheckModule
4+
WalletCheckModule,
5+
WalletCheckCustomOptions
56
} from '../../interfaces'
67
import { connectIcon } from './icons'
78

8-
function connect(
9-
options: {
10-
heading?: string
11-
description?: string
12-
icon?: string
13-
} = {}
14-
): WalletCheckModule {
15-
const { heading, description, icon } = options
9+
function connect(options: WalletCheckCustomOptions = {}): WalletCheckModule {
10+
const { heading, description, icon, html, button } = options
1611

1712
return async (
1813
stateAndHelpers: StateAndHelpers
@@ -42,7 +37,9 @@ function connect(
4237
`This dapp requires access to your wallet, please login and authorize access to your ${wallet.name} accounts to continue.`,
4338
eventCode: 'loginFail',
4439
action: wallet.connect,
45-
icon: icon || connectIcon
40+
icon: icon || connectIcon,
41+
html,
42+
button
4643
}
4744
}
4845
}

src/modules/check/network.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { networkName } from '../../utilities'
2-
import { WalletCheckModal, StateAndHelpers } from '../../interfaces'
2+
import {
3+
WalletCheckModal,
4+
StateAndHelpers,
5+
WalletCheckCustomOptions
6+
} from '../../interfaces'
37
import { networkIcon } from './icons'
48

59
function network(
6-
options: {
7-
heading?: string
8-
description?: string
9-
icon?: string
10-
} = {}
10+
options: WalletCheckCustomOptions = {}
1111
): (currentState: StateAndHelpers) => Promise<WalletCheckModal | undefined> {
12-
const { heading, description, icon } = options
12+
const { heading, description, icon, html, button } = options
1313

1414
return async (stateAndHelpers: StateAndHelpers) => {
1515
const {
@@ -48,13 +48,14 @@ function network(
4848
appNetworkId
4949
)} network</b> for this Dapp. <br><br> <i style="font-size: inherit; font-family: inherit;">*Some wallets may not support changing networks. If you can not change networks in your wallet you may consider switching to a different wallet.</i>`,
5050
eventCode: 'networkFail',
51-
button: {
51+
button: button || {
5252
onclick: () => {
5353
exit()
5454
walletSelect()
5555
},
5656
text: 'Switch Wallet'
5757
},
58+
html,
5859
icon: icon || networkIcon
5960
}
6061
}

src/modules/select/wallets/ledger.ts

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,8 @@ async function ledgerProvider(options: {
137137
let transport: any
138138
let eth: any
139139

140-
try {
141-
transport = LedgerTransport
142-
? await LedgerTransport.create()
143-
: await TransportU2F.create()
144-
145-
eth = new Eth(transport)
146-
} catch (error) {
147-
throw new Error('Error connecting to Ledger wallet')
148-
}
149-
150140
function disconnect() {
151-
transport.close()
141+
transport && transport.close()
152142
dPath = ''
153143
addressToPath = new Map()
154144
enabled = false
@@ -183,6 +173,32 @@ async function ledgerProvider(options: {
183173
return customPath
184174
}
185175

176+
async function createTransport() {
177+
try {
178+
transport = LedgerTransport
179+
? await LedgerTransport.create()
180+
: await TransportU2F.create()
181+
182+
eth = new Eth(transport)
183+
184+
const observer = {
185+
next: (event: any) => {
186+
if (event.type === 'remove') {
187+
disconnect()
188+
}
189+
},
190+
error: () => {},
191+
complete: () => {}
192+
}
193+
194+
LedgerTransport
195+
? LedgerTransport.listen(observer)
196+
: TransportU2F.listen(observer)
197+
} catch (error) {
198+
throw new Error('Error connecting to Ledger wallet')
199+
}
200+
}
201+
186202
function enable() {
187203
enabled = true
188204
return getAccounts()
@@ -205,6 +221,10 @@ async function ledgerProvider(options: {
205221
}
206222

207223
async function getAddress(path: string) {
224+
if (!eth) {
225+
await createTransport()
226+
}
227+
208228
try {
209229
const result = await eth.getAddress(path)
210230
return result.address
@@ -216,6 +236,10 @@ async function ledgerProvider(options: {
216236
throw new Error('a derivation path is needed to get the public key')
217237
}
218238

239+
if (!eth) {
240+
await createTransport()
241+
}
242+
219243
try {
220244
const result = await eth.getAddress(dPath, false, true)
221245
const { publicKey, chainCode } = result

src/validation.ts

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,68 @@ function validateWalletCheck(
337337
validateWalletCheckModule(check)
338338
} else {
339339
validateType({ name: 'walletCheck item', value: check, type: 'object' })
340-
const { checkName, minimumBalance, ...otherParams } = check
340+
const {
341+
checkName,
342+
heading,
343+
description,
344+
minimumBalance,
345+
html,
346+
icon,
347+
button,
348+
...otherParams
349+
} = check
350+
341351
invalidParams(
342352
otherParams,
343-
['checkName', 'minimumBalance'],
353+
[
354+
'checkName',
355+
'heading',
356+
'description',
357+
'html',
358+
'icon',
359+
'button',
360+
'minimumBalance'
361+
],
344362
'walletCheck item'
345363
)
364+
346365
validateType({ name: 'checkName', value: checkName, type: 'string' })
366+
367+
validateType({
368+
name: 'heading',
369+
value: heading,
370+
type: 'string',
371+
optional: true
372+
})
373+
374+
validateType({
375+
name: 'description',
376+
value: description,
377+
type: 'string',
378+
optional: true
379+
})
380+
381+
validateType({
382+
name: 'html',
383+
value: html,
384+
type: 'string',
385+
optional: true
386+
})
387+
388+
validateType({
389+
name: 'icon',
390+
value: icon,
391+
type: 'string',
392+
optional: true
393+
})
394+
395+
validateType({
396+
name: 'button',
397+
value: button,
398+
type: 'object',
399+
optional: true
400+
})
401+
347402
validateType({
348403
name: 'minimumBalance',
349404
value: minimumBalance,
@@ -520,33 +575,6 @@ export function validateWalletInterface(
520575
})
521576
}
522577

523-
export function validateWalletCheckInit(
524-
walletCheckInit: WalletCheckInit[]
525-
): void | never {
526-
validateType({
527-
name: 'walletCheckInit',
528-
value: walletCheckInit,
529-
type: 'array'
530-
})
531-
532-
walletCheckInit.forEach(init => {
533-
validateType({ name: 'walletCheckInit', value: init, type: 'object' })
534-
535-
validateType({
536-
name: 'walletCheckInit.checkName',
537-
value: init.checkName,
538-
type: 'string'
539-
})
540-
541-
validateType({
542-
name: 'walletCheckInit.minimumBalance',
543-
value: init.minimumBalance,
544-
type: 'string',
545-
optional: true
546-
})
547-
})
548-
}
549-
550578
export function validateWalletInit(
551579
walletInit: WalletInitOptions
552580
): void | never {

0 commit comments

Comments
 (0)