Skip to content

Commit 2b761ac

Browse files
authored
Merge pull request #142 from blocknative/develop
Release 1.1.7
2 parents 56fb77a + b2e38e6 commit 2b761ac

18 files changed

+139
-181
lines changed

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.1.6",
3+
"version": "1.1.7",
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",
@@ -27,10 +27,9 @@
2727
"@pyoner/svelte-ts-preprocess": "^1.2.1",
2828
"@rollup/plugin-json": "^4.0.0",
2929
"@types/lodash.debounce": "^4.0.6",
30-
"@types/node": "^12.12.3",
3130
"babel-plugin-external-helpers": "^6.18.0",
3231
"rimraf": "^3.0.0",
33-
"rollup": "^1.12.0",
32+
"rollup": "^1.27.5",
3433
"rollup-plugin-commonjs": "^10.0.0",
3534
"rollup-plugin-img": "^1.1.0",
3635
"rollup-plugin-node-resolve": "^5.2.0",
@@ -49,7 +48,6 @@
4948
"bowser": "^2.5.2",
5049
"fortmatic": "^0.8.2",
5150
"lodash.debounce": "^4.0.8",
52-
"promise-cancelable": "^2.1.1",
5351
"regenerator-runtime": "^0.13.3",
5452
"squarelink": "^1.1.4"
5553
},

rollup.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ export default {
4242
importee === 'svelte' || importee.startsWith('svelte/')
4343
}),
4444
commonjs(),
45-
typescript()
45+
typescript({
46+
clean: true
47+
})
4648
],
4749
external: [
4850
'bowser',
4951
'bnc-sdk',
5052
'bignumber.js',
51-
'promise-cancelable',
5253
'@portis/web3',
5354
'@walletconnect/web3-provider',
5455
'fortmatic',

src/@types/images.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/@types/svelte-i18n.d.ts renamed to src/@types/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
declare module 'fortmatic'
2+
declare module 'squarelink'
3+
declare module '@walletconnect/web3-provider'
4+
5+
declare module '*.png'
6+
declare module '*.svg'
7+
18
declare module 'svelte-i18n' {
29
interface Options {
310
fallback: string

src/@types/libraries.d.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/components/Wallets.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
</li>
7070
{/each}
7171

72-
{#if modalData.secondaryWallets && !showingAllWalletModules}
72+
{#if modalData.secondaryWallets && modalData.secondaryWallets.length && !showingAllWalletModules}
7373
<div>
7474
<Button onclick={() => (showingAllWalletModules = true)}>
7575
Show More

src/interfaces.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,11 @@ export interface AppState {
208208
walletCheckCompleted: boolean
209209
}
210210

211-
export interface QuerablePromise extends CancelablePromise {
212-
isFulfilled: () => boolean
213-
isResolved: () => boolean
214-
isRejected: () => boolean
211+
export interface CancelablePromise extends Promise<any> {
212+
cancel: () => void
215213
}
216214

217-
export interface CancelablePromise extends Promise<any> {
218-
cancel: (func: () => void) => void
215+
export interface QueryablePromise extends CancelablePromise {
219216
isFulfilled: () => boolean
220217
isResolved: () => boolean
221218
isRejected: () => boolean

src/modules/select/wallets/authereum.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,33 @@ function authereum(options: {
2424
iconSrc: authereumIcon,
2525
wallet: async () => {
2626
const { default: Authereum } = await import('authereum')
27-
const authereum = new Authereum({
27+
const instance = new Authereum({
2828
networkName: networkName(networkId),
2929
disableNotifications: true
3030
})
3131

32-
const provider = authereum.getProvider()
32+
const provider = instance.getProvider()
3333

3434
return {
3535
provider,
36+
instance,
3637
interface: {
3738
name: 'Authereum',
3839
connect: () => provider.enable(),
39-
disconnect: () => authereum.logout(),
40+
disconnect: () => instance.logout(),
4041
loading: new Promise((resolve: () => void) => {
41-
authereum.on('openPopup', resolve)
42+
instance.on('openPopup', resolve)
4243
}),
4344
address: {
44-
get: () => authereum.getAccountAddress()
45+
get: () => instance.getAccountAddress()
4546
},
4647
network: {
4748
get: () => Promise.resolve(networkId)
4849
},
4950
balance: {
5051
get: async () => {
51-
const loggedIn = await authereum.isAuthenticated()
52-
return loggedIn && authereum.getBalance()
52+
const loggedIn = await instance.isAuthenticated()
53+
return loggedIn && instance.getBalance()
5354
}
5455
}
5556
}

src/modules/select/wallets/fortmatic.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,17 @@ function fortmatic(options: SdkWalletOptions): WalletModule {
3030
optional: true
3131
})
3232

33-
let instance: any
34-
let provider: any
35-
3633
return {
3734
name: 'Fortmatic',
3835
svg: fortmaticIcon,
3936
wallet: async (helpers: Helpers) => {
40-
if (!instance) {
41-
const { default: Fortmatic } = await import('fortmatic')
37+
const { default: Fortmatic } = await import('fortmatic')
4238

43-
instance = new Fortmatic(
44-
apiKey,
45-
networkId === 1 ? undefined : networkName(networkId)
46-
)
47-
provider = instance.getProvider()
48-
}
39+
const instance = new Fortmatic(
40+
apiKey,
41+
networkId === 1 ? undefined : networkName(networkId)
42+
)
43+
const provider = instance.getProvider()
4944

5045
const { BigNumber } = helpers
5146

src/modules/select/wallets/portis.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,13 @@ function portis(options: SdkWalletOptions): WalletModule {
2020
optional: true
2121
})
2222

23-
let instance: any
24-
let provider: any
25-
2623
return {
2724
name: 'Portis',
2825
svg: portisIcon,
2926
wallet: async (helpers: Helpers) => {
30-
if (!instance) {
31-
const { default: Portis } = await import('@portis/web3')
32-
instance = new Portis(apiKey, networkName(networkId))
33-
provider = instance.provider
34-
}
27+
const { default: Portis } = await import('@portis/web3')
28+
const instance = new Portis(apiKey, networkName(networkId))
29+
const provider = instance.provider
3530

3631
const { BigNumber } = helpers
3732

src/modules/select/wallets/squarelink.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,17 @@ function squarelink(options: SdkWalletOptions): WalletModule {
2929
optional: true
3030
})
3131

32-
let instance: any
33-
let provider: any
34-
3532
return {
3633
name: 'Squarelink',
3734
svg: sqlkIcon,
3835
wallet: async (helpers: Helpers) => {
39-
if (!instance) {
40-
const { default: Squarelink } = await import('squarelink')
36+
const { default: Squarelink } = await import('squarelink')
4137

42-
instance = new Squarelink(apiKey, networkName(networkId), {
43-
useSync: true
44-
})
38+
const instance = new Squarelink(apiKey, networkName(networkId), {
39+
useSync: true
40+
})
4541

46-
provider = instance.getProviderSync()
47-
}
42+
const provider = instance.getProviderSync()
4843

4944
const { BigNumber } = helpers
5045

src/modules/select/wallets/wallet-connect.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,19 @@ function walletConnect(options: WalletConnectOptions): WalletModule {
3030
optional: true
3131
})
3232

33-
let provider: any
34-
3533
return {
3634
name: 'WalletConnect',
3735
svg: walletConnectIcon,
3836
wallet: async () => {
39-
if (!provider) {
40-
const { default: WalletConnectProvider } = await import(
41-
'@walletconnect/web3-provider'
42-
)
37+
const { default: WalletConnectProvider } = await import(
38+
'@walletconnect/web3-provider'
39+
)
4340

44-
provider = new WalletConnectProvider({
45-
infuraId: infuraKey
46-
})
41+
const provider = new WalletConnectProvider({
42+
infuraId: infuraKey
43+
})
4744

48-
provider.autoRefreshOnNetworkChange = false
49-
}
45+
provider.autoRefreshOnNetworkChange = false
5046

5147
return {
5248
provider,
@@ -64,10 +60,6 @@ function walletConnect(options: WalletConnectOptions): WalletModule {
6460
})
6561
)
6662
}),
67-
disconnect: () => {
68-
provider.close()
69-
provider = undefined
70-
},
7163
address: {
7264
onChange: func => {
7365
provider

src/stores.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
import { writable, derived, get } from 'svelte/store'
21
import { getBlocknative } from './services'
3-
import { wait, makeQuerablePromise } from './utilities'
2+
import { writable, derived, get } from 'svelte/store'
3+
import debounce from 'lodash.debounce'
4+
import { wait, makeQueryablePromise, makeCancelable } from './utilities'
45
import { validateWalletInterface, validateType } from './validation'
56
import {
67
WritableStore,
78
WalletInterfaceStore,
89
WalletInterface,
910
WalletStateSliceStore,
1011
StateSyncer,
11-
BalanceStore
12+
BalanceStore,
13+
QueryablePromise
1214
} from './interfaces'
1315

14-
const { default: Cancelable } = require('promise-cancelable')
15-
const debounce = require('lodash.debounce')
16-
1716
export const app: WritableStore = writable({
1817
dappId: '',
1918
networkId: 1,
@@ -23,11 +22,12 @@ export const app: WritableStore = writable({
2322
walletSelectInProgress: false,
2423
walletSelectCompleted: false,
2524
walletCheckInProgress: false,
26-
walletCheckCompleted: false
25+
walletCheckCompleted: false,
26+
autoSelectWallet: ''
2727
})
2828

2929
export const balanceSyncStatus: {
30-
syncing: null | Promise<undefined>
30+
syncing: null | QueryablePromise
3131
error: string
3232
} = {
3333
syncing: null,
@@ -253,22 +253,7 @@ function syncStateWithTimeout(options: {
253253
return () => {}
254254
}
255255

256-
const prom = makeQuerablePromise(
257-
new Cancelable(
258-
(
259-
resolve: (val: string | number | null) => void,
260-
reject: (err: any) => void,
261-
onCancel: (callback: () => void) => void
262-
) => {
263-
getState().then(resolve)
264-
265-
onCancel(() => {
266-
balanceSyncStatus.error =
267-
'There was a problem getting the balance of this wallet'
268-
})
269-
}
270-
).catch(() => {})
271-
)
256+
const prom = makeCancelable(getState())
272257

273258
balanceSyncStatus.syncing = prom
274259

@@ -286,10 +271,8 @@ function syncStateWithTimeout(options: {
286271
const timedOut = wait(timeout)
287272

288273
timedOut.then(() => {
289-
if (!prom.isFulfilled()) {
290-
prom.cancel(() => {})
291-
}
274+
prom.cancel()
292275
})
293276

294-
return () => prom.cancel(() => {})
277+
return () => prom.cancel()
295278
}

0 commit comments

Comments
 (0)