Skip to content

Commit ffb8744

Browse files
Merge pull request #678 from blocknative/release/1.34.2
Release: 1.34.2 - Master
2 parents b1bb100 + af5754e commit ffb8744

File tree

11 files changed

+1845
-81
lines changed

11 files changed

+1845
-81
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bnc-onboard",
3-
"version": "1.34.1",
3+
"version": "1.34.2",
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",
@@ -63,12 +63,13 @@
6363
"@ledgerhq/hw-app-eth": "^5.49.0",
6464
"@ledgerhq/hw-transport-u2f": "^5.21.0",
6565
"@ledgerhq/hw-transport-webusb": "5.53.0",
66+
"@myetherwallet/mewconnect-web-client": "^2.2.0-beta.11",
6667
"@portis/web3": "^4.0.0",
6768
"@shapeshiftoss/hdwallet-core": "^1.15.2",
6869
"@shapeshiftoss/hdwallet-keepkey": "^1.15.2",
6970
"@shapeshiftoss/hdwallet-keepkey-webusb": "^1.15.2",
7071
"@toruslabs/torus-embed": "^1.10.11",
71-
"@walletconnect/web3-provider": "^1.6.0",
72+
"@walletconnect/web3-provider": "^1.6.2",
7273
"authereum": "^0.1.12",
7374
"bignumber.js": "^9.0.0",
7475
"bnc-sdk": "^3.4.1",
@@ -82,7 +83,7 @@
8283
"hdkey": "^2.0.1",
8384
"regenerator-runtime": "^0.13.7",
8485
"trezor-connect": "^8.1.9",
85-
"walletlink": "^2.1.6",
86+
"walletlink": "^2.1.9",
8687
"web3-provider-engine": "^15.0.4"
8788
},
8889
"resolutions": {

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default {
5555
})
5656
],
5757
external: [
58+
'@myetherwallet/mewconnect-web-client',
5859
'bowser',
5960
'bnc-sdk',
6061
'bignumber.js',

src/interfaces.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ export interface WalletConnectOptions extends CommonWalletOptions {
198198
bridge: string
199199
}
200200

201+
export interface MewConnectOptions extends CommonWalletOptions {
202+
rpcUrl: string
203+
}
204+
201205
/*
202206
* Types taken from https://github.com/ethereumjs/ethereumjs-vm/blob/eb05651554ec23d2ba7c46af6e5f5a7bc199f217/packages/common/src/types.ts#L15
203207
* since they are not exported

src/modules/check/network.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ function network(
1414
): (currentState: StateAndHelpers) => Promise<WalletCheckModal | undefined> {
1515
const { heading, description, icon, html, button } = options
1616

17+
let networkCheckRequested = false
18+
let prevWalletCheckInProgressValue: boolean
19+
20+
app.subscribe(({ walletCheckInProgress }: AppState) => {
21+
if (
22+
prevWalletCheckInProgressValue === false &&
23+
walletCheckInProgress === true
24+
) {
25+
networkCheckRequested = false
26+
}
27+
prevWalletCheckInProgressValue = walletCheckInProgress
28+
})
29+
1730
return async (stateAndHelpers: StateAndHelpers) => {
1831
const {
1932
network,
@@ -42,8 +55,13 @@ function network(
4255
}
4356
}
4457
// Adds a check for WalletConnect since it hangs for unsupported rpc methods
45-
if (getProviderName(wallet?.provider) !== 'WalletConnect') {
58+
if (
59+
!networkCheckRequested &&
60+
stateStore.network.get() != appNetworkId &&
61+
getProviderName(wallet?.provider) !== 'WalletConnect'
62+
) {
4663
try {
64+
networkCheckRequested = true
4765
await wallet?.provider?.request({
4866
method: 'wallet_switchEthereumChain',
4967
params: [{ chainId: '0x' + appNetworkId?.toString(16) }]

src/modules/select/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ function getModule(name: string): Promise<{
194194
return import('./wallets/detectedwallet')
195195
case 'tp':
196196
return import('./wallets/tp')
197+
case 'mewwallet':
198+
return import('./wallets/mewwallet')
197199
default:
198200
throw new Error(`${name} is not a valid walletName.`)
199201
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const mewWalletIcon = `
2+
<svg width="69" height="84" viewBox="0 0 69 84" fill="none" xmlns="http://www.w3.org/2000/svg">
3+
<path d="M50.8393 79.1764C68.2511 79.9999 70.0067 64.7764 64.9062 55.9113C59.9651 47.3231 52.5533 44.3819 40.5663 45.5101C28.5793 46.6382 40.6179 66.167 48.8417 64.7349C52.5727 64.0851 49.3351 79.1052 50.8393 79.1764Z" fill="white" stroke="black" stroke-width="2.5"/>
4+
<path d="M18.5716 79.1764C1.15985 79.9999 -0.595807 64.7764 4.50465 55.9113C9.44582 47.3231 16.8576 44.3819 28.8446 45.5101C40.8316 46.6382 28.793 66.167 20.5692 64.7349C16.8382 64.0851 20.0758 79.1052 18.5716 79.1764Z" fill="white" stroke="black" stroke-width="2.5"/>
5+
<path d="M36.8853 2C42.8371 2 46.7021 2.95655 50.0569 4.75274C53.4116 6.54894 56.0445 9.18478 57.8386 12.5434C59.6134 15.8658 60.5675 19.6882 60.5882 25.5385V29.0935C60.5882 35.0521 59.6327 38.9216 57.8386 42.2802C56.0445 45.6387 53.4116 48.2746 50.0569 50.0708C46.7021 51.867 42.8371 52.8235 36.8853 52.8235H32.5263C26.5746 52.8235 22.7095 51.867 19.3548 50.0708C16 48.2746 13.3672 45.6387 11.5731 42.2802C9.77894 38.9216 8.82349 35.0521 8.82349 29.0935V25.73C8.82349 19.7714 9.77894 15.902 11.5731 12.5434C13.3672 9.18478 16 6.54894 19.3548 4.75274C22.6735 2.97586 26.4915 2.02067 32.3351 2H36.8853Z" fill="white" stroke="black" stroke-width="2.5"/>
6+
<path d="M31.5546 16.5884H37.8571C41.05 16.5884 43.5238 17.1771 45.6 18.2827C47.6762 19.3883 49.3056 21.0107 50.4159 23.078C51.5263 25.1452 52.1176 27.6083 52.1176 30.7875V31.5657C52.1176 34.7449 51.5263 37.208 50.4159 39.2753C49.3056 41.3425 47.6762 42.9649 45.6 44.0705C43.5238 45.1761 41.05 45.7648 37.8571 45.7648H31.5546C28.3617 45.7648 25.8879 45.1761 23.8117 44.0705C21.7355 42.9649 20.1061 41.3425 18.9958 39.2753C17.8854 37.208 17.2941 34.7449 17.2941 31.5657V30.7875C17.2941 27.6083 17.8854 25.1452 18.9958 23.078C20.1061 21.0107 21.7355 19.3883 23.8117 18.2827C25.8879 17.1771 28.3617 16.5884 31.5546 16.5884Z" fill="white" stroke="black" stroke-width="2.5"/>
7+
<path d="M23.6471 35.1764C25.7262 35.1764 27.4118 33.4909 27.4118 31.4117C27.4118 29.3325 25.7262 27.647 23.6471 27.647C21.5679 27.647 19.8823 29.3325 19.8823 31.4117C19.8823 33.4909 21.5679 35.1764 23.6471 35.1764Z" fill="black"/>
8+
<path d="M45.7647 35.1764C47.8439 35.1764 49.5294 33.4909 49.5294 31.4117C49.5294 29.3325 47.8439 27.647 45.7647 27.647C43.6855 27.647 42 29.3325 42 31.4117C42 33.4909 43.6855 35.1764 45.7647 35.1764Z" fill="black"/>
9+
<path d="M30.7059 30.7058C30.7059 32.785 32.4968 34.4705 34.7059 34.4705C36.915 34.4705 38.7059 32.785 38.7059 30.7058" stroke="black" stroke-width="2.5" stroke-linecap="round"/>
10+
<path d="M8.76134 16.657C9.88657 16.8159 10.8627 17.2232 11.6465 17.8212C12.4304 18.4192 13.0219 19.2079 13.3779 20.1298C13.734 21.0517 13.8545 22.1068 13.6964 23.2374L13.5524 24.2669C13.3942 25.3976 12.9889 26.3784 12.3938 27.1659C11.7986 27.9535 11.0136 28.5479 10.0961 28.9056C9.17862 29.2634 8.12859 29.3845 7.00336 29.2256C5.87813 29.0667 4.90201 28.6595 4.11818 28.0615C3.33435 27.4635 2.74281 26.6747 2.38677 25.7528C2.03073 24.8309 1.91018 23.7758 2.06832 22.6452L2.21232 21.6157C2.37046 20.4851 2.77577 19.5043 3.37092 18.7167C3.96607 17.9291 4.75106 17.3347 5.66857 16.977C6.58608 16.6193 7.63612 16.4981 8.76134 16.657Z" fill="white" stroke="black" stroke-width="2.5"/>
11+
<path d="M7.3113 20.6058L6.78593 24" stroke="#D8D8D8" stroke-width="3.2551" stroke-linecap="round" stroke-linejoin="round"/>
12+
<path d="M60.6261 16.6553C59.5042 16.8095 58.5321 17.2033 57.752 17.7817C56.9719 18.3602 56.384 19.1233 56.0304 20.0161C55.6769 20.9088 55.5578 21.9313 55.7154 23.0285L55.9161 24.4248C56.0738 25.522 56.4764 26.4727 57.0679 27.2356C57.6594 27.9985 58.4396 28.5736 59.3525 28.9193C60.2654 29.2651 61.3109 29.3816 62.4327 29.2274C63.5546 29.0732 64.5268 28.6794 65.3068 28.1009C66.0869 27.5225 66.6749 26.7594 67.0284 25.8666C67.382 24.9738 67.5011 23.9513 67.3434 22.8541L67.1428 21.4579C66.9851 20.3607 66.5824 19.4099 65.991 18.647C65.3995 17.8841 64.6192 17.3091 63.7063 16.9633C62.7935 16.6175 61.748 16.501 60.6261 16.6553Z" fill="white" stroke="black" stroke-width="2.5"/>
13+
<path d="M62.0948 20.6058L62.6202 24" stroke="#D8D8D8" stroke-width="3.2551" stroke-linecap="round" stroke-linejoin="round"/>
14+
<path d="M34.7059 41.0588C23.3998 41.0588 14.2353 50.2242 14.2353 61.5294C14.2353 72.8346 23.4007 82 34.7059 82C46.0111 82 55.1765 72.8346 55.1765 61.5294C55.1765 50.2242 46.0124 41.0588 34.7059 41.0588Z" fill="#07A6B3"/>
15+
<path d="M34.7059 41.0588C23.3998 41.0588 14.2353 50.2242 14.2353 61.5294C14.2353 72.8346 23.4007 82 34.7059 82C46.0111 82 55.1765 72.8346 55.1765 61.5294C55.1765 50.2242 46.0124 41.0588 34.7059 41.0588Z" stroke="black" stroke-width="2.5"/>
16+
<path d="M22.6436 56.9085L28.2068 59.2747C28.1888 59.3523 28.1659 59.4541 28.1402 59.5685C27.9738 60.1104 27.8758 60.6709 27.8486 61.237C27.8366 61.3492 27.8324 61.4621 27.8361 61.5749L27.841 61.6525C27.866 63.7213 28.8297 65.6671 30.4611 66.9428C32.0926 68.2184 34.2156 68.6861 36.2331 68.2144L39.3955 73.5761C37.9066 74.1691 36.3179 74.4727 34.7149 74.4707C27.7426 74.4707 21.7647 68.8272 21.7647 61.8638C21.7647 60.2289 22.0761 58.3419 22.6436 56.9085ZM34.7162 48.5884C41.6885 48.5884 47.647 54.3364 47.647 61.2981C47.6458 63.0587 47.4325 64.8154 46.7982 66.3475L46.665 66.6498L32.5437 60.6758L41.6018 60.6363C41.2764 57.3558 37.8997 54.6891 34.7153 54.6891C33.9932 54.6885 33.2759 54.8079 32.5931 55.0426L29.459 49.7298C31.1085 48.9752 32.9019 48.5858 34.7162 48.5884Z" fill="white"/>
17+
<path d="M12.8156 74.8756L11.289 70.5934C10.1268 67.3334 11.8665 63.7609 15.1748 62.6138L15.2492 62.5885C18.6253 61.4641 22.2897 63.2236 23.4707 66.5361L24.9974 70.8184C26.1596 74.0783 24.4198 77.6509 21.1115 78.798L21.0371 78.8232C17.6611 79.9477 13.9966 78.1881 12.8156 74.8756Z" fill="white" stroke="black" stroke-width="2.5"/>
18+
<path d="M22.6823 66.3056L18 67.8824" stroke="black" stroke-width="2.5" stroke-linecap="round"/>
19+
<path d="M24.4579 70.2743L19.7962 71.9126" stroke="black" stroke-width="2.5" stroke-linecap="round"/>
20+
<path d="M56.6472 74.8756L58.1738 70.5934C59.336 67.3334 57.5963 63.7609 54.288 62.6138L54.2136 62.5885C50.8375 61.4641 47.1731 63.2236 45.9921 66.5361L44.4655 70.8184C43.3033 74.0783 45.043 77.6509 48.3513 78.798L48.4257 78.8232C51.8018 79.9477 55.4662 78.1881 56.6472 74.8756Z" fill="white" stroke="black" stroke-width="2.5"/>
21+
<path d="M46.7804 66.3056L51.4628 67.8824" stroke="black" stroke-width="2.5" stroke-linecap="round"/>
22+
<path d="M45.0049 70.2743L49.6666 71.9126" stroke="black" stroke-width="2.5" stroke-linecap="round"/>
23+
</svg>
24+
`
25+
26+
export default mewWalletIcon

src/modules/select/wallets/coinbase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function coinbase(options: CommonWalletOptions): WalletModule {
2424
}
2525
},
2626
type: 'injected',
27-
link: 'https://go.cb-w.com/',
27+
link: `https://go.cb-w.com/xoXnYwQimhb?cb_url=${window.location.href}`,
2828
installMessage: mobileWalletInstallMessage,
2929
mobile: true,
3030
preferred

src/modules/select/wallets/keystone.ts

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async function keystoneProvider(options: {
9393

9494
let dPath = ''
9595

96-
let addressList = Array.from<string>([])
96+
let addressToIndex = new Map<string, number>()
9797
let enabled = false
9898
let customPath = false
9999

@@ -152,7 +152,7 @@ async function keystoneProvider(options: {
152152
function disconnect() {
153153
dPath = ''
154154
enabled = false
155-
addressList = []
155+
addressToIndex = new Map<string, number>()
156156
provider.stop()
157157
}
158158

@@ -178,12 +178,32 @@ async function keystoneProvider(options: {
178178
})
179179
}
180180

181+
function addresses() {
182+
return Array.from(addressToIndex.keys())
183+
}
184+
185+
function generateAccountsMap(accounts: string[]) {
186+
const _map = new Map<string, number>()
187+
accounts.forEach((account, index) => {
188+
_map.set(account, index)
189+
})
190+
return _map
191+
}
192+
181193
function setPrimaryAccount(address: string) {
182-
const index = addressList.findIndex(addr => addr === address) || 0
183-
keyring.setCurrentAccount(index)
184-
const accounts = [...addressList]
185-
accounts.unshift(accounts.splice(index, 1)[0])
186-
addressList = accounts
194+
// make a copy and put in an array
195+
const accounts = [...addressToIndex.entries()]
196+
const account = accounts.find(
197+
([accountAddress]) => accountAddress === address
198+
)!
199+
const accountIndex = accounts.findIndex(
200+
([accountAddress]) => accountAddress === address
201+
)
202+
keyring.setCurrentAccount(account?.[1] || 0)
203+
// pull the item at the account index out of the array and place at the front
204+
accounts.unshift(accounts.splice(accountIndex, 1)[0])
205+
// reassign addressToPath to new ordered accounts
206+
addressToIndex = new Map(accounts)
187207
}
188208

189209
function getPrimaryAddress() {
@@ -200,18 +220,21 @@ async function keystoneProvider(options: {
200220
return []
201221
}
202222

203-
if (addressList.length > 0 && !getMore) {
204-
return addressList
223+
if (addressToIndex.size > 0 && !getMore) {
224+
return addresses()
205225
}
206226

207227
try {
208-
addressList = await keyring.addAccounts(keyring.getAccounts().length + 5)
228+
const accounts = await keyring.addAccounts(
229+
keyring.getAccounts().length + 5
230+
)
231+
addressToIndex = generateAccountsMap(accounts)
209232
const currentPrimary = getPrimaryAddress()
210233
setPrimaryAccount(currentPrimary)
211234
} catch (error) {
212235
throw error
213236
}
214-
return addressList
237+
return addresses()
215238
}
216239

217240
function getBalances(addresses: Array<string>) {
@@ -250,7 +273,7 @@ async function keystoneProvider(options: {
250273
}
251274

252275
async function signTransaction(transactionData: any) {
253-
if (addressList.length === 0) {
276+
if (addressToIndex.size === 0) {
254277
await enable()
255278
}
256279

@@ -278,7 +301,7 @@ async function keystoneProvider(options: {
278301
}
279302

280303
async function signMessage(message: { data: string }): Promise<string> {
281-
if (addressList.length === 0) {
304+
if (addressToIndex.size === 0) {
282305
await enable()
283306
}
284307

@@ -290,7 +313,7 @@ async function keystoneProvider(options: {
290313
}
291314

292315
async function signTypedMessage({ data }: { data: any }) {
293-
if (addressList.length === 0) {
316+
if (addressToIndex.size === 0) {
294317
await enable()
295318
}
296319

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { MewConnectOptions, WalletModule, Helpers } from '../../../interfaces'
2+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
3+
// @ts-ignore
4+
import MEWWallet from '@myetherwallet/mewconnect-web-client'
5+
import mewWalletIcon from '../wallet-icons/icon-mew-wallet'
6+
7+
function mewConnect(options: MewConnectOptions): WalletModule {
8+
const { rpcUrl, iconSrc, networkId, preferred } = options
9+
10+
return {
11+
name: 'MEW Wallet',
12+
svg: mewWalletIcon,
13+
iconSrc: iconSrc || mewWalletIcon,
14+
wallet: async (helpers: Helpers) => {
15+
const { resetWalletState, getBalance, getAddress, getNetwork } = helpers
16+
const mewConnect = new MEWWallet.Provider({
17+
windowClosedError: true,
18+
chainId: networkId,
19+
rpcUrl
20+
})
21+
const provider = mewConnect.makeWeb3Provider()
22+
if (mewConnect.isConnected) {
23+
mewConnect.disconnect()
24+
resetWalletState({ disconnected: true, walletName: 'MEW Wallet' })
25+
}
26+
mewConnect.on('popupWindowClosed', () => {
27+
resetWalletState({ disconnected: true, walletName: 'MEW Wallet' })
28+
})
29+
return {
30+
provider,
31+
interface: {
32+
name: 'MEW Wallet',
33+
connect: () =>
34+
new Promise((resolve, reject) => {
35+
provider
36+
.enable()
37+
.then(resolve)
38+
.catch(() => {
39+
reject({
40+
message:
41+
'This dapp needs access to your account information.'
42+
})
43+
})
44+
}),
45+
address: {
46+
get: () => getAddress(provider)
47+
},
48+
network: {
49+
get: () => getNetwork(provider)
50+
},
51+
balance: {
52+
get: () => getBalance(provider)
53+
},
54+
disconnect: () => {
55+
mewConnect.disconnect()
56+
resetWalletState({ disconnected: true, walletName: 'MEW Wallet' })
57+
}
58+
}
59+
}
60+
},
61+
type: 'injected',
62+
desktop: true,
63+
preferred
64+
}
65+
}
66+
67+
export default mewConnect

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"exclude": ["node_modules/*"],
44
"compilerOptions": {
55
/* Basic Options */
6-
"target": "ESNEXT" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
7-
"module": "ESNEXT" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
6+
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
7+
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
88
// "lib": [], /* Specify library files to be included in the compilation. */
99
// "allowJs": true, /* Allow javascript files to be compiled. */
1010
// "checkJs": true, /* Report errors in .js files. */

0 commit comments

Comments
 (0)