Skip to content

Commit

Permalink
Merge pull request #142 from blocknative/develop
Browse files Browse the repository at this point in the history
Release 1.1.7
  • Loading branch information
lnbc1QWFyb24 authored Nov 28, 2019
2 parents 56fb77a + b2e38e6 commit 2b761ac
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 181 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bnc-onboard",
"version": "1.1.6",
"version": "1.1.7",
"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.",
"keywords": [
"ethereum",
Expand All @@ -27,10 +27,9 @@
"@pyoner/svelte-ts-preprocess": "^1.2.1",
"@rollup/plugin-json": "^4.0.0",
"@types/lodash.debounce": "^4.0.6",
"@types/node": "^12.12.3",
"babel-plugin-external-helpers": "^6.18.0",
"rimraf": "^3.0.0",
"rollup": "^1.12.0",
"rollup": "^1.27.5",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-img": "^1.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
Expand All @@ -49,7 +48,6 @@
"bowser": "^2.5.2",
"fortmatic": "^0.8.2",
"lodash.debounce": "^4.0.8",
"promise-cancelable": "^2.1.1",
"regenerator-runtime": "^0.13.3",
"squarelink": "^1.1.4"
},
Expand Down
5 changes: 3 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ export default {
importee === 'svelte' || importee.startsWith('svelte/')
}),
commonjs(),
typescript()
typescript({
clean: true
})
],
external: [
'bowser',
'bnc-sdk',
'bignumber.js',
'promise-cancelable',
'@portis/web3',
'@walletconnect/web3-provider',
'fortmatic',
Expand Down
2 changes: 0 additions & 2 deletions src/@types/images.d.ts

This file was deleted.

7 changes: 7 additions & 0 deletions src/@types/svelte-i18n.d.ts → src/@types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
declare module 'fortmatic'
declare module 'squarelink'
declare module '@walletconnect/web3-provider'

declare module '*.png'
declare module '*.svg'

declare module 'svelte-i18n' {
interface Options {
fallback: string
Expand Down
12 changes: 0 additions & 12 deletions src/@types/libraries.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/Wallets.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
</li>
{/each}

{#if modalData.secondaryWallets && !showingAllWalletModules}
{#if modalData.secondaryWallets && modalData.secondaryWallets.length && !showingAllWalletModules}
<div>
<Button onclick={() => (showingAllWalletModules = true)}>
Show More
Expand Down
9 changes: 3 additions & 6 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,11 @@ export interface AppState {
walletCheckCompleted: boolean
}

export interface QuerablePromise extends CancelablePromise {
isFulfilled: () => boolean
isResolved: () => boolean
isRejected: () => boolean
export interface CancelablePromise extends Promise<any> {
cancel: () => void
}

export interface CancelablePromise extends Promise<any> {
cancel: (func: () => void) => void
export interface QueryablePromise extends CancelablePromise {
isFulfilled: () => boolean
isResolved: () => boolean
isRejected: () => boolean
Expand Down
15 changes: 8 additions & 7 deletions src/modules/select/wallets/authereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,33 @@ function authereum(options: {
iconSrc: authereumIcon,
wallet: async () => {
const { default: Authereum } = await import('authereum')
const authereum = new Authereum({
const instance = new Authereum({
networkName: networkName(networkId),
disableNotifications: true
})

const provider = authereum.getProvider()
const provider = instance.getProvider()

return {
provider,
instance,
interface: {
name: 'Authereum',
connect: () => provider.enable(),
disconnect: () => authereum.logout(),
disconnect: () => instance.logout(),
loading: new Promise((resolve: () => void) => {
authereum.on('openPopup', resolve)
instance.on('openPopup', resolve)
}),
address: {
get: () => authereum.getAccountAddress()
get: () => instance.getAccountAddress()
},
network: {
get: () => Promise.resolve(networkId)
},
balance: {
get: async () => {
const loggedIn = await authereum.isAuthenticated()
return loggedIn && authereum.getBalance()
const loggedIn = await instance.isAuthenticated()
return loggedIn && instance.getBalance()
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions src/modules/select/wallets/fortmatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,17 @@ function fortmatic(options: SdkWalletOptions): WalletModule {
optional: true
})

let instance: any
let provider: any

return {
name: 'Fortmatic',
svg: fortmaticIcon,
wallet: async (helpers: Helpers) => {
if (!instance) {
const { default: Fortmatic } = await import('fortmatic')
const { default: Fortmatic } = await import('fortmatic')

instance = new Fortmatic(
apiKey,
networkId === 1 ? undefined : networkName(networkId)
)
provider = instance.getProvider()
}
const instance = new Fortmatic(
apiKey,
networkId === 1 ? undefined : networkName(networkId)
)
const provider = instance.getProvider()

const { BigNumber } = helpers

Expand Down
11 changes: 3 additions & 8 deletions src/modules/select/wallets/portis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@ function portis(options: SdkWalletOptions): WalletModule {
optional: true
})

let instance: any
let provider: any

return {
name: 'Portis',
svg: portisIcon,
wallet: async (helpers: Helpers) => {
if (!instance) {
const { default: Portis } = await import('@portis/web3')
instance = new Portis(apiKey, networkName(networkId))
provider = instance.provider
}
const { default: Portis } = await import('@portis/web3')
const instance = new Portis(apiKey, networkName(networkId))
const provider = instance.provider

const { BigNumber } = helpers

Expand Down
15 changes: 5 additions & 10 deletions src/modules/select/wallets/squarelink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,17 @@ function squarelink(options: SdkWalletOptions): WalletModule {
optional: true
})

let instance: any
let provider: any

return {
name: 'Squarelink',
svg: sqlkIcon,
wallet: async (helpers: Helpers) => {
if (!instance) {
const { default: Squarelink } = await import('squarelink')
const { default: Squarelink } = await import('squarelink')

instance = new Squarelink(apiKey, networkName(networkId), {
useSync: true
})
const instance = new Squarelink(apiKey, networkName(networkId), {
useSync: true
})

provider = instance.getProviderSync()
}
const provider = instance.getProviderSync()

const { BigNumber } = helpers

Expand Down
22 changes: 7 additions & 15 deletions src/modules/select/wallets/wallet-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,19 @@ function walletConnect(options: WalletConnectOptions): WalletModule {
optional: true
})

let provider: any

return {
name: 'WalletConnect',
svg: walletConnectIcon,
wallet: async () => {
if (!provider) {
const { default: WalletConnectProvider } = await import(
'@walletconnect/web3-provider'
)
const { default: WalletConnectProvider } = await import(
'@walletconnect/web3-provider'
)

provider = new WalletConnectProvider({
infuraId: infuraKey
})
const provider = new WalletConnectProvider({
infuraId: infuraKey
})

provider.autoRefreshOnNetworkChange = false
}
provider.autoRefreshOnNetworkChange = false

return {
provider,
Expand All @@ -64,10 +60,6 @@ function walletConnect(options: WalletConnectOptions): WalletModule {
})
)
}),
disconnect: () => {
provider.close()
provider = undefined
},
address: {
onChange: func => {
provider
Expand Down
39 changes: 11 additions & 28 deletions src/stores.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { writable, derived, get } from 'svelte/store'
import { getBlocknative } from './services'
import { wait, makeQuerablePromise } from './utilities'
import { writable, derived, get } from 'svelte/store'
import debounce from 'lodash.debounce'
import { wait, makeQueryablePromise, makeCancelable } from './utilities'
import { validateWalletInterface, validateType } from './validation'
import {
WritableStore,
WalletInterfaceStore,
WalletInterface,
WalletStateSliceStore,
StateSyncer,
BalanceStore
BalanceStore,
QueryablePromise
} from './interfaces'

const { default: Cancelable } = require('promise-cancelable')
const debounce = require('lodash.debounce')

export const app: WritableStore = writable({
dappId: '',
networkId: 1,
Expand All @@ -23,11 +22,12 @@ export const app: WritableStore = writable({
walletSelectInProgress: false,
walletSelectCompleted: false,
walletCheckInProgress: false,
walletCheckCompleted: false
walletCheckCompleted: false,
autoSelectWallet: ''
})

export const balanceSyncStatus: {
syncing: null | Promise<undefined>
syncing: null | QueryablePromise
error: string
} = {
syncing: null,
Expand Down Expand Up @@ -253,22 +253,7 @@ function syncStateWithTimeout(options: {
return () => {}
}

const prom = makeQuerablePromise(
new Cancelable(
(
resolve: (val: string | number | null) => void,
reject: (err: any) => void,
onCancel: (callback: () => void) => void
) => {
getState().then(resolve)

onCancel(() => {
balanceSyncStatus.error =
'There was a problem getting the balance of this wallet'
})
}
).catch(() => {})
)
const prom = makeCancelable(getState())

balanceSyncStatus.syncing = prom

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

timedOut.then(() => {
if (!prom.isFulfilled()) {
prom.cancel(() => {})
}
prom.cancel()
})

return () => prom.cancel(() => {})
return () => prom.cancel()
}
Loading

0 comments on commit 2b761ac

Please sign in to comment.