Skip to content

Commit 70e36f3

Browse files
committed
Merge branch 'v2-web3-onboard-develop' of blocknative.github.com:blocknative/onboard into v2-web3-onboard-develop
2 parents 3a91656 + 7c80e49 commit 70e36f3

File tree

20 files changed

+386
-407
lines changed

20 files changed

+386
-407
lines changed

README.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@
1212

1313
## Quickstart
1414

15-
Install the core Onboard library and the injected wallets module to support browser extension and mobile wallets:
15+
Install the core Onboard library, the injected wallets module and optionally ethers js to support browser extension and mobile wallets:
1616

17-
`npm i @web3-onboard/core @web3-onboard/injected-wallets`
17+
**NPM**
18+
`npm i @web3-onboard/core @web3-onboard/injected-wallets ethers`
1819

19-
- [@web3-onboard/core Official NPM Documentation](https://www.npmjs.com/package/@web3-onboard/core)
20+
**Yarn**
21+
`yarn add @web3-onboard/core @web3-onboard/injected-wallets ethers`
2022

2123
Then initialize in your app:
2224

2325
```javascript
2426
import Onboard from '@web3-onboard/core'
2527
import injectedModule from '@web3-onboard/injected-wallets'
28+
import { ethers } from 'ethers'
2629

2730
const MAINNET_RPC_URL = 'https://mainnet.infura.io/v3/<INFURA_KEY>'
2831

@@ -37,17 +40,31 @@ const onboard = Onboard({
3740
label: 'Ethereum Mainnet',
3841
rpcUrl: MAINNET_RPC_URL
3942
}
40-
],
41-
appMetadata: {
42-
name: 'My App',
43-
icon: '<SVG_ICON_STRING>',
44-
description: 'My app using Onboard'
45-
}
43+
]
4644
})
4745

4846
const wallets = await onboard.connectWallet()
4947

5048
console.log(wallets)
49+
50+
if (wallets[0]) {
51+
// create an ethers provider with the last connected wallet provider
52+
const ethersProvider = new ethers.providers.Web3Provider(
53+
wallets[0].provider,
54+
'any'
55+
)
56+
57+
const signer = ethersProvider.getSigner()
58+
59+
// send a transaction with the ethers provider
60+
const txn = await signer.sendTransaction({
61+
to: '0x',
62+
value: 100000000000000
63+
})
64+
65+
const receipt = await txn.wait()
66+
console.log(receipt)
67+
}
5168
```
5269

5370
## Documentation
@@ -64,22 +81,23 @@ For full documentation, check out the README.md for each package:
6481

6582
**SDK Wallets**
6683

67-
- [Fortmatic](packages/fortmatic/README.md)
84+
- [Coinbase](packages/coinbase/README.md)
85+
- [WalletConnect](packages/walletconnect/README.md)
6886
- [Gnosis](packages/gnosis/README.md)
69-
- [MEW](packages/mew/README.md)
87+
- [Magic](packages/magic/README.md)
88+
- [Fortmatic](packages/fortmatic/README.md)
7089
- [Portis](packages/portis/README.md)
71-
- [Torus](packages/torus/README.md)
72-
- [WalletConnect](packages/walletconnect/README.md)
73-
- [WalletLink](packages/walletlink/README.md)
74-
- Magic (in active development)
90+
- [MEW](packages/mew/README.md)
91+
- [Web3Auth](packages/web3auth/README.md)
7592

7693
**Hardware Wallets**
7794

78-
- [KeepKey](packages/keepkey/README.md)
7995
- [Ledger](packages/ledger/README.md)
8096
- [Trezor](packages/trezor/README.md)
8197
- [Keystone](packages/keystone/README.md)
98+
- [KeepKey](packages/keepkey/README.md)
8299
- [D'CENT](packages/dcent/README.md)
100+
83101
**Frameworks**
84102

85103
- [React](packages/react/README.md)

packages/core/README.md

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Note:
1717
- MEW wallet currently fails to install on M1 macs
1818
- All wallet modules (except for `injected-wallets`) require extra dependencies and may require polyfilling the node built in modules for the browser. See the [Build Environments](#build-environments) section for more info
1919
- **If using React** you may be interested in checking out the React Hooks package here - https://www.npmjs.com/package/@web3-onboard/react
20+
- **If using Vue** you may be interested in checking out the Vue package here - https://www.npmjs.com/package/@web3-onboard/vue
2021

2122
## Initialization
2223

@@ -147,7 +148,12 @@ unsubscribe()
147148
```
148149

149150
```typescript
151+
150152
export type NotifyOptions = {
153+
desktop: Notify
154+
mobile: Notify
155+
}
156+
export type Notify = {
151157
enabled: boolean // default: true
152158
/**
153159
* Callback that receives all transaction events
@@ -158,8 +164,15 @@ export type NotifyOptions = {
158164
transactionHandler?: (
159165
event: EthereumTransactionData
160166
) => TransactionHandlerReturn
167+
position: CommonPositions
161168
}
162169

170+
export type CommonPositions =
171+
| 'topRight'
172+
| 'bottomRight'
173+
| 'bottomLeft'
174+
| 'topLeft'
175+
163176
export type TransactionHandlerReturn = CustomNotification | boolean | void
164177

165178
export type CustomNotification = Partial<Omit<Notification, 'id' | 'startTime'>>
@@ -285,15 +298,31 @@ const onboard = Onboard({
285298
},
286299
apiKey: 'xxx387fb-bxx1-4xxc-a0x3-9d37e426xxxx'
287300
notify: {
288-
enabled: true,
289-
transactionHandler: transaction => {
290-
console.log({ transaction })
291-
if (transaction.eventCode === 'txPool') {
292-
return {
293-
type: 'success',
294-
message: 'Your transaction from #1 DApp is in the mempool',
301+
desktop: {
302+
enabled: true,
303+
transactionHandler: transaction => {
304+
console.log({ transaction })
305+
if (transaction.eventCode === 'txPool') {
306+
return {
307+
type: 'success',
308+
message: 'Your transaction from #1 DApp is in the mempool',
309+
}
295310
}
296-
}
311+
},
312+
position: 'bottomLeft'
313+
},
314+
mobile: {
315+
enabled: true,
316+
transactionHandler: transaction => {
317+
console.log({ transaction })
318+
if (transaction.eventCode === 'txPool') {
319+
return {
320+
type: 'success',
321+
message: 'Your transaction from #1 DApp is in the mempool',
322+
}
323+
}
324+
},
325+
position: 'topRight'
297326
}
298327
},
299328
accountCenter: {
@@ -420,7 +449,7 @@ type AppState = {
420449
accountCenter: AccountCenter
421450
walletModules: WalletModule[]
422451
locale: Locale
423-
notify: NotifyOptions
452+
notify: Notify
424453
notifications: Notification[]
425454
}
426455

packages/core/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/core",
3-
"version": "2.3.1-alpha.3",
3+
"version": "2.3.1-alpha.4",
44
"scripts": {
55
"build": "rollup -c",
66
"dev": "rollup -c -w",

packages/core/src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export const APP_INITIAL_STATE: AppState = {
1313
},
1414
notify: {
1515
enabled: true,
16-
transactionHandler: () => {}
16+
transactionHandler: () => {},
17+
position: 'topRight'
1718
},
1819
notifications: [],
1920
locale: ''

packages/core/src/index.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import disconnectWallet from './disconnect'
44
import setChain from './chain'
55
import { state } from './store'
66
import { reset$ } from './streams'
7-
import { validateInitOptions } from './validation'
7+
import { validateInitOptions, validateNotify, validateNotifyOptions } from './validation'
88
import initI18N from './i18n'
99
import App from './views/Index.svelte'
10-
import type { InitOptions, OnboardAPI } from './types'
10+
import type { InitOptions, OnboardAPI, Notify } from './types'
1111
import { APP_INITIAL_STATE } from './constants'
1212
import { configuration, updateConfiguration } from './configuration'
1313

@@ -22,7 +22,7 @@ import {
2222

2323
import updateBalances from './updateBalances'
2424

25-
const API = {
25+
const API: OnboardAPI = {
2626
connectWallet,
2727
disconnectWallet,
2828
setChain,
@@ -51,7 +51,7 @@ export type {
5151
AppState,
5252
CustomNotification,
5353
Notification,
54-
NotifyOptions,
54+
Notify,
5555
UpdateNotification
5656
} from './types'
5757

@@ -104,7 +104,50 @@ function init(options: InitOptions): OnboardAPI {
104104

105105
// update notify
106106
if (typeof notify !== undefined) {
107-
updateNotify(notify)
107+
if ('desktop' in notify || 'mobile' in notify) {
108+
const error = validateNotifyOptions(notify)
109+
110+
if (error) {
111+
throw error
112+
}
113+
114+
if (
115+
(!notify.desktop || (notify.desktop && !notify.desktop.position)) &&
116+
accountCenter &&
117+
accountCenter.desktop &&
118+
accountCenter.desktop.position
119+
) {
120+
notify.desktop.position = accountCenter.desktop.position
121+
}
122+
if (
123+
(!notify.mobile || (notify.mobile && !notify.mobile.position)) &&
124+
accountCenter &&
125+
accountCenter.mobile &&
126+
accountCenter.mobile.position
127+
) {
128+
notify.mobile.position = accountCenter.mobile.position
129+
}
130+
let notifyUpdate: Partial<Notify>
131+
if (device.type === 'mobile' && notify.mobile) {
132+
notifyUpdate = {
133+
...APP_INITIAL_STATE.notify,
134+
...notify.mobile
135+
}
136+
} else if (notify.desktop) {
137+
notifyUpdate = {
138+
...APP_INITIAL_STATE.notify,
139+
...notify.desktop
140+
}
141+
}
142+
updateNotify(notifyUpdate)
143+
} else {
144+
const error = validateNotify(notify as Notify)
145+
146+
if (error) {
147+
throw error
148+
}
149+
updateNotify(notify as Notify)
150+
}
108151
}
109152

110153
if (svelteInstance) {

packages/core/src/store/actions.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import type {
1616
UpdateAccountCenterAction,
1717
UpdateWalletAction,
1818
WalletState,
19-
NotifyOptions,
2019
UpdateNotifyAction,
2120
Notification,
2221
AddNotificationAction,
2322
RemoveNotificationAction,
2423
UpdateAllWalletsAction,
2524
CustomNotification,
2625
UpdateNotification,
27-
CustomNotificationUpdate
26+
CustomNotificationUpdate,
27+
Notify
2828
} from '../types'
2929

3030
import {
@@ -33,11 +33,11 @@ import {
3333
validateNotification,
3434
validateCustomNotification,
3535
validateCustomNotificationUpdate,
36-
validateNotifyOptions,
3736
validateString,
3837
validateWallet,
3938
validateWalletInit,
40-
validateUpdateBalances
39+
validateUpdateBalances,
40+
validateNotify
4141
} from '../validation'
4242

4343
import {
@@ -156,8 +156,8 @@ export function updateAccountCenter(
156156
dispatch(action as UpdateAccountCenterAction)
157157
}
158158

159-
export function updateNotify(update: Partial<NotifyOptions>): void {
160-
const error = validateNotifyOptions(update)
159+
export function updateNotify(update: Partial<Notify>): void {
160+
const error = validateNotify(update)
161161

162162
if (error) {
163163
throw error

0 commit comments

Comments
 (0)