Skip to content

Commit db4672d

Browse files
authored
[core:2.6.0-alpha.3] [common:2.1.7-alpha.2] - [feature] : Gas Module (#1168)
* Initial implementation of Gas module * Working prototype * Add docs * Modify API * Add override poll example and comment * Remove gas module from demo * Update usage in core * Update gas API * Revert changes to fix types * Revert changes to types that are in another pr * Fix docs * Revert in favor of PR * Fix Configuration types * Fix validation * Remove gas from demo * Increment versions * Correct version for demo * Use joi version in other pkgs, update yarn.lock
1 parent c1bcc7d commit db4672d

File tree

20 files changed

+475
-157
lines changed

20 files changed

+475
-157
lines changed

.circleci/config.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ jobs:
285285
working_directory: ~/web3-onboard-monorepo/packages/vue
286286
steps:
287287
- node-build-steps
288+
build-gas:
289+
docker:
290+
- image: cimg/node:16.13.1
291+
working_directory: ~/web3-onboard-monorepo/packages/gas
292+
steps:
293+
- node-build-steps
288294

289295
# Build staging/Alpha releases
290296
build-staging-core:
@@ -407,6 +413,12 @@ jobs:
407413
working_directory: ~/web3-onboard-monorepo/packages/vue
408414
steps:
409415
- node-staging-build-steps
416+
build-staging-gas:
417+
docker:
418+
- image: cimg/node:16.13.1
419+
working_directory: ~/web3-onboard-monorepo/packages/gas
420+
steps:
421+
- node-staging-build-steps
410422

411423
workflows:
412424
version: 2
@@ -531,3 +543,9 @@ workflows:
531543
<<: *deploy_production_filters
532544
- build-staging-vue:
533545
<<: *deploy_staging_filters
546+
gas:
547+
jobs:
548+
- build-gas:
549+
<<: *deploy_production_filters
550+
- build-staging-gas:
551+
<<: *deploy_staging_filters

packages/common/src/index.ts

Lines changed: 1 addition & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,3 @@
1-
import type {
2-
RequestPatch,
3-
AccountSelectAPI,
4-
SelectAccountOptions,
5-
BasePath,
6-
DerivationPath,
7-
Asset,
8-
ScanAccounts,
9-
ScanAccountsOptions,
10-
AccountAddress,
11-
Account,
12-
AccountsList,
13-
AppMetadata,
14-
RecommendedInjectedWallets,
15-
WalletInit,
16-
WalletHelpers,
17-
APIKey,
18-
Device,
19-
WalletModule,
20-
GetInterfaceHelpers,
21-
Platform,
22-
DeviceOS,
23-
DeviceBrowser,
24-
DeviceOSName,
25-
DeviceBrowserName,
26-
DeviceType,
27-
ChainId,
28-
RpcUrl,
29-
WalletInterface,
30-
ProviderMessage,
31-
ProviderInfo,
32-
ProviderAccounts,
33-
ProviderEvent,
34-
SimpleEventEmitter,
35-
ConnectListener,
36-
DisconnectListener,
37-
MessageListener,
38-
ChainListener,
39-
AccountsListener,
40-
Balance,
41-
EthAccountsRequest,
42-
EthBalanceRequest,
43-
EIP1102Request,
44-
SelectAccountsRequest,
45-
EIP3326Request,
46-
EIP3085Request,
47-
EthChainIdRequest,
48-
EthSignTransactionRequest,
49-
EthSignMessageRequest,
50-
EIP712Request,
51-
AddChainParams,
52-
EIP1193Provider,
53-
Chain,
54-
TokenSymbol,
55-
CustomNetwork,
56-
TransactionObject,
57-
RPCResponse
58-
} from './types'
59-
601
export { ProviderRpcErrorCode } from './types'
612
export { ProviderRpcError } from './errors'
623
export { createEIP1193Provider } from './eip-1193'
@@ -69,61 +10,4 @@ export {
6910
getHardwareWalletProvider
7011
} from './hdwallets'
7112

72-
export type {
73-
RequestPatch,
74-
AccountSelectAPI,
75-
SelectAccountOptions,
76-
BasePath,
77-
DerivationPath,
78-
Asset,
79-
ScanAccounts,
80-
ScanAccountsOptions,
81-
AccountAddress,
82-
Account,
83-
AccountsList,
84-
AppMetadata,
85-
RecommendedInjectedWallets,
86-
WalletInit,
87-
WalletHelpers,
88-
APIKey,
89-
Device,
90-
WalletModule,
91-
GetInterfaceHelpers,
92-
Platform,
93-
DeviceOS,
94-
DeviceBrowser,
95-
DeviceOSName,
96-
DeviceBrowserName,
97-
DeviceType,
98-
ChainId,
99-
RpcUrl,
100-
WalletInterface,
101-
ProviderMessage,
102-
ProviderInfo,
103-
ProviderAccounts,
104-
ProviderEvent,
105-
SimpleEventEmitter,
106-
ConnectListener,
107-
DisconnectListener,
108-
MessageListener,
109-
ChainListener,
110-
AccountsListener,
111-
Balance,
112-
EthAccountsRequest,
113-
EthBalanceRequest,
114-
EIP1102Request,
115-
SelectAccountsRequest,
116-
EIP3326Request,
117-
EIP3085Request,
118-
EthChainIdRequest,
119-
EthSignTransactionRequest,
120-
EthSignMessageRequest,
121-
EIP712Request,
122-
AddChainParams,
123-
EIP1193Provider,
124-
Chain,
125-
TokenSymbol,
126-
CustomNetwork,
127-
TransactionObject,
128-
RPCResponse
129-
}
13+
export * from './types'

packages/core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/core",
3-
"version": "2.6.0-alpha.4",
3+
"version": "2.6.0-alpha.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",
@@ -68,6 +68,7 @@
6868
"@types/lodash.partition": "^4.6.6",
6969
"@typescript-eslint/eslint-plugin": "^4.31.1",
7070
"@typescript-eslint/parser": "^4.31.1",
71+
"@web3-onboard/gas": "^2.0.0",
7172
"eslint": "^7.32.0",
7273
"eslint-config-prettier": "^8.3.0",
7374
"eslint-plugin-svelte3": "^3.2.1",

packages/core/src/configuration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export let configuration: Configuration = {
66
appMetadata: null,
77
apiKey: null,
88
device: getDevice(),
9-
initialWalletInit: []
9+
initialWalletInit: [],
10+
gas: null
1011
}
1112

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

packages/core/src/index.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ import disconnectWallet from './disconnect'
44
import setChain from './chain'
55
import { state } from './store'
66
import { reset$ } from './streams'
7-
import {
8-
validateInitOptions,
9-
validateNotify,
10-
validateNotifyOptions
11-
} from './validation'
127
import initI18N from './i18n'
138
import App from './views/Index.svelte'
149
import type { InitOptions, Notify } from './types'
1510
import { APP_INITIAL_STATE } from './constants'
1611
import { configuration, updateConfiguration } from './configuration'
12+
import updateBalances from './update-balances'
13+
import { chainIdToHex } from './utils'
14+
import { preflightNotifications } from './preflight-notifications'
15+
16+
import {
17+
validateInitOptions,
18+
validateNotify,
19+
validateNotifyOptions
20+
} from './validation'
1721

1822
import {
1923
addChains,
@@ -25,10 +29,6 @@ import {
2529
setWalletModules
2630
} from './store/actions'
2731

28-
import updateBalances from './update-balances'
29-
import { chainIdToHex } from './utils'
30-
import { preflightNotifications } from './preflight-notifications'
31-
3232
const API = {
3333
connectWallet,
3434
disconnectWallet,
@@ -86,11 +86,13 @@ function init(options: InitOptions): OnboardAPI {
8686
i18n,
8787
accountCenter,
8888
apiKey,
89-
notify
89+
notify,
90+
gas
9091
} = options
9192

9293
initI18N(i18n)
9394
addChains(chains.map(chainIdToHex))
95+
9496
const { device, svelteInstance } = configuration
9597

9698
// update accountCenter
@@ -129,6 +131,7 @@ function init(options: InitOptions): OnboardAPI {
129131
) {
130132
notify.desktop.position = accountCenter.desktop.position
131133
}
134+
132135
if (
133136
(!notify.mobile || (notify.mobile && !notify.mobile.position)) &&
134137
accountCenter &&
@@ -137,6 +140,7 @@ function init(options: InitOptions): OnboardAPI {
137140
) {
138141
notify.mobile.position = accountCenter.mobile.position
139142
}
143+
140144
let notifyUpdate: Partial<Notify>
141145

142146
if (device.type === 'mobile' && notify.mobile) {
@@ -150,16 +154,19 @@ function init(options: InitOptions): OnboardAPI {
150154
...notify.desktop
151155
}
152156
}
157+
153158
if (!apiKey || !notifyUpdate.enabled) {
154159
notifyUpdate.enabled = false
155160
}
161+
156162
updateNotify(notifyUpdate)
157163
} else {
158164
const error = validateNotify(notify as Notify)
159165

160166
if (error) {
161167
throw error
162168
}
169+
163170
const notifyUpdate: Partial<Notify> = {
164171
...APP_INITIAL_STATE.notify,
165172
...notify
@@ -168,6 +175,7 @@ function init(options: InitOptions): OnboardAPI {
168175
if (!apiKey || !notifyUpdate.enabled) {
169176
notifyUpdate.enabled = false
170177
}
178+
171179
updateNotify(notifyUpdate)
172180
}
173181
} else {
@@ -176,6 +184,7 @@ function init(options: InitOptions): OnboardAPI {
176184
if (!apiKey) {
177185
notifyUpdate.enabled = false
178186
}
187+
179188
updateNotify(notifyUpdate)
180189
}
181190

@@ -191,7 +200,8 @@ function init(options: InitOptions): OnboardAPI {
191200
appMetadata,
192201
svelteInstance: app,
193202
apiKey,
194-
initialWalletInit: wallets
203+
initialWalletInit: wallets,
204+
gas
195205
})
196206

197207
return API
@@ -214,6 +224,7 @@ function mountApp() {
214224
styleEl.innerHTML = `
215225
${SofiaProRegular}
216226
`
227+
217228
document.body.appendChild(styleEl)
218229

219230
// add to DOM
@@ -317,7 +328,9 @@ function mountApp() {
317328

318329
const containerElementQuery =
319330
state.get().accountCenter.containerElement || 'body'
331+
320332
const containerElement = document.querySelector(containerElementQuery)
333+
321334
if (!containerElement) {
322335
throw new Error(
323336
`Element with query ${state.get().accountCenter} does not exist.`

packages/core/src/types.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import type {
1010
TokenSymbol
1111
} from '@web3-onboard/common'
1212

13+
import type gas from '@web3-onboard/gas'
14+
1315
import type en from './i18n/en.json'
1416
import type { EthereumTransactionData, Network } from 'bnc-sdk'
1517

@@ -43,6 +45,8 @@ export interface InitOptions {
4345
* Transaction notification options
4446
*/
4547
notify?: Partial<NotifyOptions> | Partial<Notify>
48+
/**Gas module */
49+
gas?: typeof gas
4650
}
4751

4852
export interface ConnectOptions {
@@ -116,10 +120,11 @@ export interface AppState {
116120

117121
export type Configuration = {
118122
svelteInstance: SvelteComponent | null
119-
appMetadata: AppMetadata | null
120123
device: Device | DeviceNotBrowser
121-
apiKey: string
122124
initialWalletInit: WalletInit[]
125+
appMetadata?: AppMetadata | null
126+
apiKey?: string
127+
gas?: typeof gas
123128
}
124129

125130
export type Locale = string

packages/core/src/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ export async function copyWalletAddress(text: string): Promise<void> {
9292
}
9393
}
9494

95-
export const chainIdToHex = (chain: Chain): Chain => typeof chain.id === 'number' ? { ...chain, id: `0x${chain.id.toString(16)}` } : chain
95+
export const chainIdToHex = (chain: Chain): Chain =>
96+
typeof chain.id === 'number'
97+
? { ...chain, id: `0x${chain.id.toString(16)}` }
98+
: chain
9699

97100
export const chainIdToLabel: Record<string, string> = {
98101
'0x1': 'Ethereum',
@@ -245,5 +248,5 @@ export const defaultNotifyEventStyles: Record<string, NotifyEventStyles> = {
245248
}
246249
}
247250

248-
export const wait = (time: number) =>
251+
export const wait = (time: number): Promise<void> =>
249252
new Promise(resolve => setTimeout(resolve, time))

0 commit comments

Comments
 (0)