Skip to content

Commit 4d34a3f

Browse files
authored
Merge pull request #1296 from blocknative/release/2.12.0
Release 2.12.0 (main)
2 parents 47e7fa1 + 4978553 commit 4d34a3f

File tree

33 files changed

+269
-170
lines changed

33 files changed

+269
-170
lines changed

.github/workflows/issue-to-notion.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ jobs:
2424
FLAG: Github
2525
STATUS: Backlog
2626
# Product Work Board
27-
DATABASE_ID: 29876f9a9b864ca39a984f42e17fd345
28-
PROJECT_NAME: Onboard.js
27+
DATABASE_ID: 69f0e513a59d445b87a1baed729c75c5
28+
PROJECT_NAME: web3-onboard
2929
# User ids of who to assign the card to in notion: Taylor, Adam, Aaron
3030
NOTION_USER_IDS: f6cbb362-4908-4138-9ef0-434003d9a9f8,8a3a2287-5d2c-4665-906d-02ae9a113340,3b407adf-6552-40de-b22f-5efa852c34a2
3131
shell: bash

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web3-onboard-monorepo",
3-
"version": "2.11.1",
3+
"version": "2.12.0",
44
"private": true,
55
"workspaces": {
66
"packages": [
@@ -51,7 +51,7 @@
5151
"url": "https://github.com/blocknative/web3-onboard.git",
5252
"directory": "packages/core"
5353
},
54-
"homepage": "https://www.blocknative.com/onboard",
54+
"homepage": "https://onboard.blocknative.com",
5555
"bugs": "https://github.com/blocknative/web3-onboard/issues",
5656
"scripts": {
5757
"install-m1-mac": "yarn install --ignore-optional",

packages/coinbase/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/coinbase",
3-
"version": "2.1.2",
3+
"version": "2.1.3",
44
"description": "Coinbase SDK wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",
@@ -38,7 +38,7 @@
3838
"url": "https://github.com/blocknative/web3-onboard.git",
3939
"directory": "packages/coinbase"
4040
},
41-
"homepage": "https://www.blocknative.com/onboard",
41+
"homepage": "https://onboard.blocknative.com",
4242
"bugs": "https://github.com/blocknative/web3-onboard/issues",
4343
"module": "dist/index.js",
4444
"browser": "dist/index.js",
@@ -59,6 +59,6 @@
5959
},
6060
"dependencies": {
6161
"@coinbase/wallet-sdk": "^3.0.5",
62-
"@web3-onboard/common": "^2.2.2"
62+
"@web3-onboard/common": "^2.2.3"
6363
}
6464
}

packages/common/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/common",
3-
"version": "2.2.2",
3+
"version": "2.2.3",
44
"description": "Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",
@@ -38,7 +38,7 @@
3838
"url": "https://github.com/blocknative/web3-onboard.git",
3939
"directory": "packages/common"
4040
},
41-
"homepage": "https://www.blocknative.com/onboard",
41+
"homepage": "https://onboard.blocknative.com",
4242
"bugs": "https://github.com/blocknative/web3-onboard/issues",
4343
"scripts": {
4444
"build": "tsc",
@@ -75,6 +75,6 @@
7575
"dependencies": {
7676
"bignumber.js": "^9.1.0",
7777
"ethers": "5.5.4",
78-
"joi": "^17.4.2"
78+
"joi": "^17.6.1"
7979
}
8080
}

packages/core/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/core",
3-
"version": "2.8.4",
3+
"version": "2.8.5",
44
"description": "Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",
@@ -39,7 +39,7 @@
3939
"url": "https://github.com/blocknative/web3-onboard.git",
4040
"directory": "packages/core"
4141
},
42-
"homepage": "https://www.blocknative.com/onboard",
42+
"homepage": "https://onboard.blocknative.com",
4343
"bugs": "https://github.com/blocknative/web3-onboard/issues",
4444
"scripts": {
4545
"build": "rollup -c",
@@ -82,13 +82,13 @@
8282
"typescript": "^4.5.5"
8383
},
8484
"dependencies": {
85-
"@web3-onboard/common": "^2.2.2",
85+
"@web3-onboard/common": "^2.2.3",
8686
"bignumber.js": "^9.0.0",
8787
"bnc-sdk": "^4.4.1",
8888
"bowser": "^2.11.0",
8989
"ethers": "5.5.3",
9090
"eventemitter3": "^4.0.7",
91-
"joi": "17.6.0",
91+
"joi": "^17.6.1",
9292
"lodash.merge": "^4.6.2",
9393
"lodash.partition": "^4.6.0",
9494
"nanoid": "^4.0.0",

packages/core/src/chain.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { firstValueFrom } from 'rxjs'
1+
import { firstValueFrom, Observable } from 'rxjs'
22
import { filter, map } from 'rxjs/operators'
3-
import { ProviderRpcErrorCode } from '@web3-onboard/common'
3+
import { Chain, ProviderRpcErrorCode } from '@web3-onboard/common'
44
import { addNewChain, switchChain } from './provider.js'
55
import { state } from './store/index.js'
66
import { switchChainModal$ } from './streams.js'
@@ -66,21 +66,17 @@ async function setChain(options: {
6666
filter(x => x === null),
6767
map(() => false)
6868
)
69-
7069
if (
7170
code === ProviderRpcErrorCode.CHAIN_NOT_ADDED ||
7271
code === ProviderRpcErrorCode.UNRECOGNIZED_CHAIN_ID
7372
) {
7473
// chain has not been added to wallet
75-
try {
76-
await addNewChain(wallet.provider, chain)
77-
await switchChain(wallet.provider, chainIdHex)
78-
return true
79-
} catch (error) {
80-
// display notification to user to switch chain
81-
switchChainModal$.next({ chain })
82-
return firstValueFrom(switchChainModalClosed$)
83-
}
74+
return chainNotInWallet(
75+
wallet,
76+
chain,
77+
switchChainModalClosed$,
78+
chainIdHex
79+
)
8480
}
8581

8682
if (code === ProviderRpcErrorCode.UNSUPPORTED_METHOD) {
@@ -93,4 +89,26 @@ async function setChain(options: {
9389
return false
9490
}
9591

92+
const chainNotInWallet = async (
93+
wallet: WalletState,
94+
chain: Chain,
95+
switchChainModalClosed$: Observable<boolean>,
96+
chainIdHex: string
97+
): Promise<boolean> => {
98+
try {
99+
await addNewChain(wallet.provider, chain)
100+
await switchChain(wallet.provider, chainIdHex)
101+
return true
102+
} catch (error) {
103+
const { code } = error as { code: number }
104+
if (code === ProviderRpcErrorCode.ACCOUNT_ACCESS_REJECTED) {
105+
// add new chain rejected by user
106+
return false
107+
}
108+
// display notification to user to switch chain
109+
switchChainModal$.next({ chain })
110+
return firstValueFrom(switchChainModalClosed$)
111+
}
112+
}
113+
96114
export default setChain

packages/core/src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
},
2626
"mainText": "Connecting...",
2727
"paragraph": "Make sure to select all accounts that you want to grant access to.",
28+
"previousConnection": "{wallet} already has a pending connection request, please open the {wallet} app to login and connect.",
2829
"rejectedText": "Connection Rejected!",
2930
"rejectedCTA": "Click here to try again",
3031
"primaryButton": "Back to wallets"

packages/core/src/views/connect/ConnectingWallet.svelte

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
export let deselectWallet: (label: string) => void
1313
export let setStep: (update: keyof i18n['connect']) => void
1414
export let connectionRejected: boolean
15+
export let previousConnectionRequest: boolean
1516
1617
const { appMetadata } = configuration
1718
</script>
@@ -69,23 +70,27 @@
6970
<div class="container flex flex-column items-center">
7071
<div
7172
class="connecting-container flex justify-between items-center"
72-
class:warning={connectionRejected}
73+
class:warning={connectionRejected || previousConnectionRequest}
7374
>
7475
<div class="flex">
7576
<div class="flex justify-center relative">
7677
<WalletAppBadge
7778
size={40}
7879
padding={8}
7980
icon={(appMetadata && appMetadata.icon) || questionIcon}
80-
border={connectionRejected ? 'yellow' : 'blue'}
81+
border={connectionRejected || previousConnectionRequest
82+
? 'yellow'
83+
: 'blue'}
8184
background="lightGray"
8285
/>
8386

8487
<div class="relative" style="right: 0.5rem;">
8588
<WalletAppBadge
8689
size={40}
8790
padding={8}
88-
border={connectionRejected ? 'yellow' : 'blue'}
91+
border={connectionRejected || previousConnectionRequest
92+
? 'yellow'
93+
: 'blue'}
8994
background="white"
9095
icon={selectedWallet.icon}
9196
/>
@@ -95,9 +100,9 @@
95100
<div class="flex flex-column justify-center ml">
96101
<div class="text" class:text-rejected={connectionRejected}>
97102
{$_(
98-
connectionRejected
99-
? 'connect.connectingWallet.rejectedText'
100-
: 'connect.connectingWallet.mainText',
103+
`connect.connectingWallet.${
104+
connectionRejected ? 'rejectedText' : 'mainText'
105+
}`,
101106
{
102107
default: connectionRejected
103108
? en.connect.connectingWallet.rejectedText
@@ -113,9 +118,15 @@
113118
</div>
114119
{:else}
115120
<div class="subtext">
116-
{$_('connect.connectingWallet.paragraph', {
117-
default: en.connect.connectingWallet.paragraph
118-
})}
121+
{$_(
122+
`connect.connectingWallet.${
123+
previousConnectionRequest ? 'previousConnection' : 'paragraph'
124+
}`,
125+
{
126+
default: en.connect.connectingWallet.paragraph,
127+
values: { wallet: selectedWallet.label }
128+
}
129+
)}
119130
</div>
120131
{/if}
121132
</div>

packages/core/src/views/connect/Index.svelte

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<script lang="ts">
22
import { ProviderRpcErrorCode, WalletModule } from '@web3-onboard/common'
3-
import { BehaviorSubject, takeUntil } from 'rxjs'
43
import EventEmitter from 'eventemitter3'
54
import { _ } from 'svelte-i18n'
65
import en from '../../i18n/en.json'
7-
import { selectAccounts } from '../../provider.js'
6+
import { listenAccountsChanged, selectAccounts } from '../../provider.js'
87
import { state } from '../../store/index.js'
98
import { connectWallet$, onDestroy$ } from '../../streams.js'
109
import { addWallet, updateAccount } from '../../store/actions.js'
@@ -20,6 +19,18 @@
2019
import { configuration } from '../../configuration.js'
2120
import { getBlocknativeSdk } from '../../services.js'
2221
import { BigNumber } from 'ethers'
22+
23+
import {
24+
BehaviorSubject,
25+
distinctUntilChanged,
26+
filter,
27+
firstValueFrom,
28+
mapTo,
29+
Subject,
30+
take,
31+
takeUntil
32+
} from 'rxjs'
33+
2334
import {
2435
getChainId,
2536
requestAccounts,
@@ -39,8 +50,10 @@
3950
4051
const { appMetadata } = configuration
4152
const { walletModules, connect } = state.get()
53+
const cancelPreviousConnect$ = new Subject<void>()
4254
4355
let connectionRejected = false
56+
let previousConnectionRequest = false
4457
let wallets: WalletWithLoadingIcon[] = []
4558
let selectedWallet: WalletState | null
4659
let agreed: boolean
@@ -54,6 +67,25 @@
5467
'selectingWallet'
5568
)
5669
70+
// handle the edge case where disableModals was set to true on first call
71+
// and then set to false on second call and there is still a pending call
72+
connectWallet$
73+
.pipe(
74+
distinctUntilChanged(
75+
(prev, curr) =>
76+
prev.autoSelect &&
77+
curr.autoSelect &&
78+
prev.autoSelect.disableModals === curr.autoSelect.disableModals
79+
),
80+
filter(
81+
({ autoSelect }) => autoSelect && autoSelect.disableModals === false
82+
),
83+
takeUntil(onDestroy$)
84+
)
85+
.subscribe(() => {
86+
selectedWallet && connectWallet()
87+
})
88+
5789
// ==== SELECT WALLET ==== //
5890
async function selectWallet({
5991
label,
@@ -161,8 +193,15 @@
161193
162194
const { provider, label } = selectedWallet
163195
196+
cancelPreviousConnect$.next()
197+
164198
try {
165-
const [address] = await requestAccounts(provider)
199+
const [address] = await Promise.race([
200+
// resolved account
201+
requestAccounts(provider),
202+
// or connect wallet is called again whilst waiting for response
203+
firstValueFrom(cancelPreviousConnect$.pipe(mapTo([])))
204+
])
166205
167206
// canceled previous request
168207
if (!address) {
@@ -216,6 +255,25 @@
216255
217256
// account access has already been requested and is awaiting approval
218257
if (code === ProviderRpcErrorCode.ACCOUNT_ACCESS_ALREADY_REQUESTED) {
258+
previousConnectionRequest = true
259+
260+
if (autoSelect.disableModals) {
261+
connectWallet$.next({ inProgress: false })
262+
return
263+
}
264+
265+
listenAccountsChanged({
266+
provider: selectedWallet.provider,
267+
disconnected$: connectWallet$.pipe(
268+
filter(({ inProgress }) => !inProgress),
269+
mapTo('')
270+
)
271+
})
272+
.pipe(take(1))
273+
.subscribe(([account]) => {
274+
account && connectWallet()
275+
})
276+
219277
return
220278
}
221279
}
@@ -286,6 +344,7 @@
286344
})
287345
288346
function setStep(update: keyof i18n['connect']) {
347+
cancelPreviousConnect$.next()
289348
modalStep$.next(update)
290349
}
291350
@@ -408,6 +467,7 @@
408467
<ConnectingWallet
409468
{connectWallet}
410469
{connectionRejected}
470+
{previousConnectionRequest}
411471
{setStep}
412472
{deselectWallet}
413473
{selectedWallet}

0 commit comments

Comments
 (0)