Skip to content

Commit 6fc5637

Browse files
Merge pull request #627 from blocknative/release/1.31.0
Release: 1.31.0 - Master
2 parents 5b6c268 + f658dfb commit 6fc5637

18 files changed

+2017
-164
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.30.0",
3+
"version": "1.31.0",
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",
@@ -54,6 +54,9 @@
5454
},
5555
"dependencies": {
5656
"@cvbb/eth-keyring": "^1.1.0",
57+
"@ensdomains/ensjs": "^2.0.1",
58+
"@ethereumjs/common": "^2.0.0",
59+
"@ethereumjs/tx": "^3.0.0",
5760
"@gnosis.pm/safe-apps-provider": "^0.5.0",
5861
"@gnosis.pm/safe-apps-sdk": "^3.0.0",
5962
"@ledgerhq/hw-app-eth": "^5.49.0",
@@ -78,7 +81,7 @@
7881
"hdkey": "^2.0.1",
7982
"regenerator-runtime": "^0.13.7",
8083
"trezor-connect": "^8.1.9",
81-
"walletlink": "^2.1.0",
84+
"walletlink": "^2.1.6",
8285
"web3-provider-engine": "^15.0.4"
8386
},
8487
"resolutions": {

pull_request_template.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Description
2+
<!-- Add a description of the fix or feature here -->
3+
4+
### Checklist
5+
- [ ] The version field in `package.json` is incremented following [semantic versioning](https://semver.org/)
6+
- [ ] The box that allows repo maintainers to update this PR is checked
7+
- [ ] I tested locally to make sure this feature/fix works
8+
- [ ] This PR passes the Circle CI checks

rollup.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export default {
6767
'regenerator-runtime/runtime',
6868
'trezor-connect',
6969
'ethereumjs-tx',
70+
'@ethereumjs/tx',
71+
'@ethereumjs/common',
7072
'ethereumjs-util',
7173
'eth-lattice-keyring',
7274
'eth-sig-util',
@@ -89,6 +91,7 @@ export default {
8991
'@shapeshiftoss/hdwallet-keepkey-webusb',
9092
'@shapeshiftoss/hdwallet-core',
9193
'@gnosis.pm/safe-apps-sdk',
92-
'@gnosis.pm/safe-apps-provider'
94+
'@gnosis.pm/safe-apps-provider',
95+
'@ensdomains/ensjs'
9396
]
9497
}

src/@types/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ declare module 'web3-provider-engine/subproviders/subscriptions'
88
declare module 'web3-provider-engine/subproviders/filters'
99
declare module 'trezor-connect'
1010
declare module 'eth-lattice-keyring'
11-
declare module 'eth-sig-util'
1211
declare module 'ethereumjs-tx'
12+
declare module '@ethereumjs/tx'
13+
declare module '@ethereumjs/common'
1314
declare module 'ethereumjs-util'
1415
declare module 'hdkey'
1516
declare module '@ledgerhq/hw-app-eth'
1617
declare module '@ledgerhq/hw-transport-u2f'
1718
declare module '@ledgerhq/hw-transport-webusb'
1819
declare module 'eth-provider'
20+
declare module '@ensdomains/ensjs'
1921

2022
declare module '@shapeshiftoss/hdwallet-core'
2123
declare module '@shapeshiftoss/hdwallet-keepkey-webusb'

src/interfaces.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface Initialization {
1313

1414
export interface Subscriptions {
1515
address?: (address: string) => void
16+
ens?: (ens: Ens) => void
1617
network?: (networkId: number) => void
1718
balance?: (balance: string) => void
1819
wallet?: (wallet: Wallet) => void
@@ -196,20 +197,66 @@ export interface WalletConnectOptions extends CommonWalletOptions {
196197
bridge: string
197198
}
198199

200+
/*
201+
* Types taken from https://github.com/ethereumjs/ethereumjs-vm/blob/eb05651554ec23d2ba7c46af6e5f5a7bc199f217/packages/common/src/types.ts#L15
202+
* since they are not exported
203+
*/
204+
205+
export interface GenesisBlock {
206+
hash: string
207+
timestamp: string | null
208+
gasLimit: number
209+
difficulty: number
210+
nonce: string
211+
extraData: string
212+
stateRoot: string
213+
}
214+
export interface Hardfork {
215+
name: string
216+
block: number | null
217+
}
218+
219+
export interface BootstrapNode {
220+
ip: string
221+
port: number | string
222+
network?: string
223+
chainId?: number
224+
id: string
225+
location: string
226+
comment: string
227+
}
228+
229+
export interface HardwareWalletCustomNetwork {
230+
networkId: number
231+
genesis: GenesisBlock
232+
hardforks: Hardfork[]
233+
bootstrapNodes: BootstrapNode[]
234+
}
235+
199236
export interface TrezorOptions extends CommonWalletOptions {
200237
appUrl: string
201238
email: string
202239
rpcUrl: string
240+
customNetwork?: HardwareWalletCustomNetwork
203241
}
204242

205243
export interface LatticeOptions extends CommonWalletOptions {
206244
appName: string
207245
rpcUrl: string
246+
customNetwork?: HardwareWalletCustomNetwork
208247
}
209248

210249
export interface LedgerOptions extends CommonWalletOptions {
211250
rpcUrl: string
212251
LedgerTransport?: any
252+
customNetwork?: HardwareWalletCustomNetwork
253+
}
254+
255+
export interface GnosisOptions extends CommonWalletOptions {
256+
// For default apps (cf. https://github.com/gnosis/safe-apps-list/issues/new/choose)
257+
appName?: string
258+
// For other apps, give the URL needed to add a custom app
259+
appUrl?: string
213260
}
214261

215262
//#region torus
@@ -513,3 +560,10 @@ export interface TermsAgreementState {
513560
terms?: boolean
514561
privacy?: boolean
515562
}
563+
564+
export interface Ens {
565+
name?: string
566+
avatar?: string
567+
contentHash?: string
568+
getText?: (key: string) => Promise<string | undefined>
569+
}

src/modules/select/index.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,23 @@ function select(
5050
: desktopDefaultWalletNames
5151

5252
if (wallets) {
53+
// For backwards compatibility if a user is still using 'detectedwallet' in the onboard wallet select array
54+
// it will be filtered out so there are no duplicates
55+
wallets = wallets.filter(
56+
wallet =>
57+
'walletName' in wallet ? wallet.walletName !== 'detectedwallet' : true // It is not a WalletInitOption but rather a WalletModule so let it through
58+
)
59+
60+
// If we detect an injected wallet then place the detected wallet
61+
// at the beginning of the list e.g. the of the wallet select modal
62+
if (injectedWalletDetected()) {
63+
wallets.unshift({ walletName: 'detectedwallet' })
64+
}
5365
return Promise.all(
54-
wallets
55-
// only include a detected wallet if it's not already one of the provided options
56-
.filter(
57-
wallet =>
58-
isWalletInit(wallet) &&
59-
(wallet.walletName !== 'detectedwallet' || injectedWalletDetected())
60-
)
61-
.map(wallet => {
62-
const { walletName, ...initParams } = wallet as WalletInitOptions
66+
wallets.map(wallet => {
67+
// If this is a wallet init object then load the built-in wallet module
68+
if (isWalletInit(wallet)) {
69+
const { walletName, ...initParams } = wallet
6370
try {
6471
return getModule(walletName).then((m: any) =>
6572
m.default({ ...initParams, networkId, isMobile })
@@ -71,15 +78,17 @@ function select(
7178
throw error
7279
}
7380
}
81+
}
7482

75-
return Promise.resolve(wallet)
76-
})
83+
// This is a custom wallet module so just return it
84+
return Promise.resolve(wallet)
85+
})
7786
)
7887
}
7988

8089
return Promise.all(
8190
defaultWalletNames
82-
// only include a detected wallet if it's not already one of the provided options
91+
// Include the detected wallet only if an injected wallet is detected
8392
.filter(
8493
walletName =>
8594
walletName !== 'detectedwallet' || injectedWalletDetected()

src/modules/select/wallets/cobovault.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function cobovaultProvider(options: {
6565
walletName: string
6666
}) => void
6767
}) {
68-
const EthereumTx = await import('ethereumjs-tx')
68+
const { Transaction } = await import('@ethereumjs/tx')
6969
const { default: createProvider } = await import('./providerEngine')
7070

7171
const BASE_PATH = "m/44'/60'/0'/0"
@@ -227,7 +227,7 @@ async function cobovaultProvider(options: {
227227
await enable()
228228
}
229229

230-
const transaction = new EthereumTx.Transaction(transactionData, {
230+
const transaction = Transaction.fromTxData(transactionData, {
231231
chain: networkName(networkId)
232232
})
233233

src/modules/select/wallets/gnosis.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type SafeAppsSDK from '@gnosis.pm/safe-apps-sdk'
22
import type { SafeInfo } from '@gnosis.pm/safe-apps-sdk'
3-
import { CommonWalletOptions, Helpers, WalletModule } from '../../../interfaces'
3+
import { GnosisOptions, Helpers, WalletModule } from '../../../interfaces'
44
import gnosisWalletIcon from '../wallet-icons/icon-gnosis'
55

66
const getSafe = (sdk: SafeAppsSDK): Promise<SafeInfo | undefined> =>
@@ -20,11 +20,16 @@ export const checkGnosisSafeContext = async (selectWallet: () => void) =>
2020
!!(await getSafe(new (await import('@gnosis.pm/safe-apps-sdk')).default())) &&
2121
selectWallet()
2222

23-
function gnosis(options: CommonWalletOptions): WalletModule {
23+
function gnosis(options: GnosisOptions): WalletModule {
2424
const { preferred, label, iconSrc, svg, networkId } = options
2525

2626
const network = networkId === 4 ? 'rinkeby.' : ''
2727
const link = `https://${network}gnosis-safe.io/app`
28+
const safeAppMessage = options.appName
29+
? `Then go to APPS and select <b>${options.appName}</b>.`
30+
: options.appUrl
31+
? `Then go to APPS and add a custom app with the URL:<br /><b>${options.appUrl}</b>`
32+
: ''
2833

2934
return {
3035
name: label || 'Gnosis Safe',
@@ -51,7 +56,8 @@ function gnosis(options: CommonWalletOptions): WalletModule {
5156
link,
5257
installMessage: () => `
5358
<p style="font-size: 0.889rem; font-family: inherit; margin: 0.889rem 0;">
54-
Click the button below to open the Gnosis Safe interface.
59+
Click the button below to open the Gnosis Safe interface.<br />
60+
${safeAppMessage}
5561
</p>
5662
`,
5763
desktop: true,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export function generateAddresses(
3737

3838
export function isValidPath(path: string) {
3939
const parts = path.split('/')
40-
4140
if (parts[0] !== 'm') {
4241
return false
4342
}
@@ -46,11 +45,11 @@ export function isValidPath(path: string) {
4645
return false
4746
}
4847

49-
if (parts[2] !== "60'" && parts[2] !== "1'") {
48+
if (!["60'", "1'", "73799'", "246'"].includes(parts[2])) {
5049
return false
5150
}
5251

53-
if (parts[3] === undefined) {
52+
if (parts[3] === undefined || parts[3] === "0'") {
5453
return true
5554
}
5655

src/modules/select/wallets/keepkey/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable @typescript-eslint/camelcase */
2+
import * as ethUtil from 'ethereumjs-util'
23
import {
34
CommonWalletOptions,
45
Helpers,
@@ -385,7 +386,7 @@ async function createKeepKeyProvider({
385386
gasPrice,
386387
gasLimit: gas,
387388
to,
388-
value: value || '',
389+
value: value || '0x0',
389390
data: data || '',
390391
chainId: networkId
391392
})
@@ -406,7 +407,7 @@ async function createKeepKeyProvider({
406407

407408
const { signature } = await keepKeyWallet.ethSignMessage({
408409
addressNList,
409-
message
410+
message: ethUtil.toBuffer(message).toString('utf8')
410411
})
411412

412413
return signature

0 commit comments

Comments
 (0)