Skip to content

Commit 7f32edf

Browse files
authored
Merge pull request #1399 from blocknative/release/2.15.0
Release 2.15.0
2 parents 60039c3 + b3204e5 commit 7f32edf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2015
-492
lines changed

.circleci/config.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ jobs:
327327
working_directory: ~/web3-onboard-monorepo/packages/uauth
328328
steps:
329329
- node-build-steps
330+
build-transaction-preview:
331+
docker:
332+
- image: cimg/node:16.13.1
333+
working_directory: ~/web3-onboard-monorepo/packages/transaction-preview
334+
steps:
335+
- node-build-steps
330336

331337
# Build staging/Alpha releases
332338
build-staging-core:
@@ -491,6 +497,12 @@ jobs:
491497
working_directory: ~/web3-onboard-monorepo/packages/uauth
492498
steps:
493499
- node-staging-build-steps
500+
build-staging-transaction-preview:
501+
docker:
502+
- image: cimg/node:16.13.1
503+
working_directory: ~/web3-onboard-monorepo/packages/transaction-preview
504+
steps:
505+
- node-staging-build-steps
494506

495507
workflows:
496508
version: 2
@@ -657,3 +669,9 @@ workflows:
657669
<<: *deploy_production_filters
658670
- build-staging-uauth:
659671
<<: *deploy_staging_filters
672+
transaction-preview:
673+
jobs:
674+
- build-transaction-preview:
675+
<<: *deploy_production_filters
676+
- build-staging-transaction-preview:
677+
<<: *deploy_staging_filters

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web3-onboard-monorepo",
3-
"version": "2.14.2",
3+
"version": "2.15.0",
44
"private": true,
55
"workspaces": {
66
"packages": [

packages/coinbase/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/coinbase",
3-
"version": "2.1.3",
3+
"version": "2.2.0",
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",
@@ -58,7 +58,7 @@
5858
"typescript": "^4.5.5"
5959
},
6060
"dependencies": {
61-
"@coinbase/wallet-sdk": "^3.0.5",
61+
"@coinbase/wallet-sdk": "^3.6.0",
6262
"@web3-onboard/common": "^2.2.3"
6363
}
6464
}

packages/coinbase/src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,22 @@ function coinbaseWallet({
1313
const [chain] = chains
1414
const { name, icon } = appMetadata || {}
1515

16-
const { CoinbaseWalletSDK } = await import('@coinbase/wallet-sdk')
16+
// according to https://github.com/wagmi-dev/wagmi/issues/383
17+
// @coinbase/wallet-sdk export double default fields
18+
// so we need to detect it to get the real constructor
19+
const { default: CoinbaseWalletSDK } = await import(
20+
'@coinbase/wallet-sdk'
21+
)
22+
const CoinbaseWalletSDKConstructor = (
23+
(CoinbaseWalletSDK as any).default
24+
? (CoinbaseWalletSDK as any).default
25+
: CoinbaseWalletSDK
26+
) as typeof CoinbaseWalletSDK
1727

1828
const base64 = window.btoa(icon || '')
1929
const appLogoUrl = `data:image/svg+xml;base64,${base64}`
2030

21-
const instance = new CoinbaseWalletSDK({
31+
const instance = new CoinbaseWalletSDKConstructor({
2232
appName: name || '',
2333
appLogoUrl,
2434
darkMode

packages/core/README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ type InitOptions {
3333
apiKey?: string
3434
notify?: Partial<NotifyOptions>
3535
connect?: Partial<ConnectModalOptions>
36+
gas?: typeof gas
37+
/**
38+
* Object mapping for W3O components with the key being the component and the value the DOM element to mount the component to. This element must be available at time of package script execution.
39+
*/
40+
containerElements?: Partial<ContainerElements>
3641
}
3742
```
3843

@@ -78,13 +83,6 @@ type AppMetadata = {
7883
explore?: string
7984
// if your app only supports injected wallets and when no injected wallets detected, recommend the user to install some
8085
recommendedInjectedWallets?: RecommendedInjectedWallets[]
81-
/** Gas module */
82-
gas?: typeof gas
83-
/**
84-
* Object mapping for W3O components with the key being the component and the value the DOM element to mount
85-
* the component to. This element must be available at time of package script execution.
86-
*/
87-
containerElements?: Partial<ContainerElements>
8886
}
8987

9088
type RecommendedInjectedWallets = {

packages/core/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/core",
3-
"version": "2.10.1",
3+
"version": "2.11.0",
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",
@@ -69,6 +69,7 @@
6969
"@typescript-eslint/eslint-plugin": "^4.31.1",
7070
"@typescript-eslint/parser": "^4.31.1",
7171
"@web3-onboard/gas": "^2.0.0",
72+
"@web3-onboard/transaction-preview": "^2.0.0",
7273
"eslint": "^7.32.0",
7374
"eslint-config-prettier": "^8.3.0",
7475
"eslint-plugin-svelte3": "^3.2.1",
@@ -84,7 +85,7 @@
8485
"dependencies": {
8586
"@web3-onboard/common": "^2.2.3",
8687
"bignumber.js": "^9.0.0",
87-
"bnc-sdk": "^4.4.1",
88+
"bnc-sdk": "^4.6.2",
8889
"bowser": "^2.11.0",
8990
"ethers": "5.5.3",
9091
"eventemitter3": "^4.0.7",

packages/core/src/configuration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export let configuration: Configuration = {
88
device: getDevice(),
99
initialWalletInit: [],
1010
gas: null,
11-
containerElements: { accountCenter: null }
11+
containerElements: { accountCenter: null },
12+
transactionPreview: null
1213
}
1314

1415
export function updateConfiguration(update: Partial<Configuration>): void {

packages/core/src/disconnect.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getBlocknativeSdk } from './services.js'
1+
import { getBNMulitChainSdk } from './services.js'
22
import { state } from './store/index.js'
33
import { removeWallet } from './store/actions.js'
44
import { disconnectWallet$ } from './streams.js'
@@ -15,7 +15,7 @@ async function disconnect(options: DisconnectOptions): Promise<WalletState[]> {
1515

1616
if (state.get().notify.enabled) {
1717
// handle unwatching addresses
18-
const sdk = await getBlocknativeSdk()
18+
const sdk = await getBNMulitChainSdk()
1919

2020
if (sdk) {
2121
const wallet = state.get().wallets.find(wallet => wallet.label === label)

packages/core/src/index.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import connectWallet from './connect.js'
33
import disconnectWallet from './disconnect.js'
44
import setChain from './chain.js'
55
import { state } from './store/index.js'
6-
import { reset$ } from './streams.js'
6+
import { reset$, wallets$ } from './streams.js'
77
import initI18N from './i18n/index.js'
88
import App from './views/Index.svelte'
99
import type { InitOptions, Notify } from './types.js'
@@ -29,6 +29,8 @@ import {
2929
setWalletModules,
3030
updateConnectModal
3131
} from './store/actions.js'
32+
import type { PatchedEIP1193Provider } from '@web3-onboard/transaction-preview'
33+
import { getBlocknativeSdk } from './services'
3234

3335
const API = {
3436
connectWallet,
@@ -90,7 +92,8 @@ function init(options: InitOptions): OnboardAPI {
9092
notify,
9193
gas,
9294
connect,
93-
containerElements
95+
containerElements,
96+
transactionPreview
9497
} = options
9598

9699
updateConfiguration({ containerElements })
@@ -197,9 +200,26 @@ function init(options: InitOptions): OnboardAPI {
197200
svelteInstance: app,
198201
apiKey,
199202
initialWalletInit: wallets,
200-
gas
203+
gas,
204+
transactionPreview
201205
})
202206

207+
if (transactionPreview) {
208+
const getBnSDK = async () => {
209+
transactionPreview.init({
210+
containerElement: '#transaction-preview-container',
211+
sdk: await getBlocknativeSdk(),
212+
apiKey
213+
})
214+
wallets$.subscribe(wallets => {
215+
wallets.forEach(({ provider }) => {
216+
transactionPreview.patchProvider(provider as PatchedEIP1193Provider)
217+
})
218+
})
219+
}
220+
getBnSDK()
221+
}
222+
203223
return API
204224
}
205225

packages/core/src/provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { updateAccount, updateWallet } from './store/actions.js'
88
import { validEnsChain } from './utils.js'
99
import disconnect from './disconnect.js'
1010
import { state } from './store/index.js'
11-
import { getBlocknativeSdk } from './services.js'
11+
import { getBNMulitChainSdk } from './services.js'
1212

1313
import type {
1414
ChainId,
@@ -157,7 +157,7 @@ export function trackWallet(
157157
// if not existing account and notifications,
158158
// then subscribe to transaction events
159159
if (state.get().notify.enabled && !existingAccount) {
160-
const sdk = await getBlocknativeSdk()
160+
const sdk = await getBNMulitChainSdk()
161161

162162
if (sdk) {
163163
const wallet = state
@@ -227,7 +227,7 @@ export function trackWallet(
227227
if (chainId === connectedWalletChain.id) return
228228

229229
if (state.get().notify.enabled) {
230-
const sdk = await getBlocknativeSdk()
230+
const sdk = await getBNMulitChainSdk()
231231

232232
if (sdk) {
233233
const wallet = state

packages/core/src/services.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
11
import type { MultiChain } from 'bnc-sdk'
2+
import type SDK from 'bnc-sdk'
23
import { configuration } from './configuration.js'
34
import { handleTransactionUpdates } from './notify.js'
45

5-
let blocknativeSdk: MultiChain
6+
let blocknativeMultiChainSdk: MultiChain
7+
let blocknativeSdk: SDK
68

79
/**
810
*
9-
* @returns SDK if apikey
11+
* @returns MultiChain SDK if apiKey
1012
*/
11-
export async function getBlocknativeSdk(): Promise<MultiChain | null> {
13+
14+
export async function getBNMulitChainSdk(): Promise<MultiChain | null> {
1215
const { apiKey } = configuration
1316

1417
if (!apiKey) return null
1518

16-
if (!blocknativeSdk) {
19+
if (!blocknativeMultiChainSdk) {
1720
const { default: Blocknative } = await import('bnc-sdk')
18-
blocknativeSdk = Blocknative.multichain({
21+
blocknativeMultiChainSdk = Blocknative.multichain({
1922
apiKey: configuration.apiKey
2023
})
2124

22-
blocknativeSdk.transactions$.subscribe(handleTransactionUpdates)
25+
blocknativeMultiChainSdk.transactions$.subscribe(handleTransactionUpdates)
26+
}
27+
28+
return blocknativeMultiChainSdk
29+
}
30+
31+
/**
32+
*
33+
* @returns SDK if apiKey
34+
*/
35+
export async function getBlocknativeSdk(): Promise<SDK> {
36+
const { apiKey } = configuration
37+
38+
if (!apiKey) return null
39+
40+
if (!blocknativeSdk) {
41+
const { default: Blocknative } = await import('bnc-sdk')
42+
blocknativeSdk = new Blocknative({
43+
dappId: configuration.apiKey,
44+
networkId: 1
45+
})
46+
return blocknativeSdk
2347
}
2448

2549
return blocknativeSdk

packages/core/src/types.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
} from '@web3-onboard/common'
1313

1414
import type gas from '@web3-onboard/gas'
15+
import type { TransactionPreviewAPI } from '@web3-onboard/transaction-preview'
1516

1617
import type en from './i18n/en.json'
1718
import type { EthereumTransactionData, Network } from 'bnc-sdk'
@@ -53,10 +54,15 @@ export interface InitOptions {
5354
/** Gas module */
5455
gas?: typeof gas
5556
/**
56-
* Object mapping for W3O components with the key being the DOM element to mount
57-
* the component to, this defines the DOM container element for svelte to attach the component
57+
* Object mapping for W3O components with the key being the DOM
58+
* element to mount the component to, this defines the DOM container
59+
* element for svelte to attach the component
5860
*/
5961
containerElements?: Partial<ContainerElements>
62+
/**
63+
* Transaction Preview module
64+
*/
65+
transactionPreview?: TransactionPreviewAPI
6066
}
6167

6268
export interface ConnectOptions {
@@ -137,6 +143,7 @@ export type Configuration = {
137143
apiKey?: string
138144
gas?: typeof gas
139145
containerElements?: ContainerElements
146+
transactionPreview?: TransactionPreviewAPI
140147
}
141148

142149
export type Locale = string

packages/core/src/validation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ const initOptions = Joi.object({
185185
stream: Joi.function().required()
186186
}),
187187
connect: connectModalOptions,
188-
containerElements: containerElements
188+
containerElements: containerElements,
189+
transactionPreview: Joi.object({
190+
patchProvider: Joi.function().required(),
191+
init: Joi.function().required()
192+
})
189193
})
190194

191195
const connectOptions = Joi.object({

0 commit comments

Comments
 (0)