Skip to content

Commit a6927ee

Browse files
committed
Merge in changes to gas module
2 parents 5f8c085 + 9b285dc commit a6927ee

File tree

4 files changed

+22
-45
lines changed

4 files changed

+22
-45
lines changed

packages/demo/src/App.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import coinbaseModule from '@web3-onboard/coinbase'
1414
import magicModule from '@web3-onboard/magic'
1515
import web3authModule from '@web3-onboard/web3auth'
16+
1617
import dcentModule from '@web3-onboard/dcent'
1718
import {
1819
recoverAddress,

packages/gas/src/get.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import { firstValueFrom, zip } from 'rxjs'
2-
import { map } from 'rxjs/operators'
32
import { ajax } from 'rxjs/ajax'
43
import { getRequestUrl } from './utils'
54
import { RequestOptions, ChainId, GasPlatformResponse } from './types'
65
import { validateRequest } from './validation'
76

8-
function get(
9-
options: RequestOptions
10-
): Promise<Record<ChainId, GasPlatformResponse>> {
7+
function get(options: RequestOptions): Promise<GasPlatformResponse[]> {
118
const invalid = validateRequest(options)
129

1310
if (invalid) {
@@ -26,14 +23,6 @@ function get(
2623
requestUrls.map(({ url, headers }) =>
2724
ajax.getJSON<GasPlatformResponse>(url, headers)
2825
)
29-
).pipe(
30-
// reduce to mapping of chainId -> gas data
31-
map(data =>
32-
chains.reduce((acc, chainId, index) => {
33-
acc[chainId] = data[index]
34-
return acc
35-
}, {})
36-
)
3726
)
3827
)
3928
}

packages/gas/src/stream.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { Observable, timer, zip } from 'rxjs'
2-
import { switchMap, map } from 'rxjs/operators'
2+
import { switchMap } from 'rxjs/operators'
33
import { ajax } from 'rxjs/ajax'
44
import { getRequestUrl } from './utils'
5-
import { StreamOptions, ChainId, GasPlatformResponse } from './types'
5+
import { StreamOptions, GasPlatformResponse } from './types'
66
import { validateRequest } from './validation'
77

8-
function stream(
9-
options: StreamOptions
10-
): Observable<Record<ChainId, GasPlatformResponse>> {
8+
function stream(options: StreamOptions): Observable<GasPlatformResponse[]> {
119
const invalid = validateRequest(options)
1210

1311
if (invalid) {
@@ -29,13 +27,6 @@ function stream(
2927
ajax.getJSON<GasPlatformResponse>(url, headers)
3028
)
3129
)
32-
),
33-
// reduce to mapping of chainId -> gas data
34-
map(data =>
35-
chains.reduce((acc, chainId, index) => {
36-
acc[chainId] = data[index]
37-
return acc
38-
}, {})
3930
)
4031
)
4132
}

packages/injected/src/wallets.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import type {
22
EIP1193Provider,
33
ChainListener,
4-
SimpleEventEmitter
4+
SimpleEventEmitter,
5+
ChainId
56
} from '@web3-onboard/common'
67

78
import { createEIP1193Provider } from '@web3-onboard/common'
8-
import type { InjectedWalletModule, CustomWindow } from './types.js'
9+
import type {
10+
InjectedWalletModule,
11+
CustomWindow,
12+
BinanceProvider
13+
} from './types.js'
914

1015
import {
1116
InjectedNameSpace,
@@ -65,11 +70,11 @@ const binance: InjectedWalletModule = {
6570
!!provider && !!provider[ProviderIdentityFlag.Binance],
6671
getIcon: async () => (await import('./icons/binance.js')).default,
6772
getInterface: async () => {
68-
// We add this to the BinanceChain provider as there is currently
69-
// no way to determine if the wallet is unlocked
70-
if (window.BinanceChain) {
71-
window.BinanceChain.isUnlocked = false
73+
// Replace the provider as the BNB provider is readonly
74+
let tempBNBProvider: BinanceProvider = {
75+
...window.BinanceChain
7276
}
77+
window.BinanceChain = tempBNBProvider
7378

7479
const addListener: SimpleEventEmitter['on'] = window.BinanceChain.on.bind(
7580
window.BinanceChain
@@ -78,31 +83,22 @@ const binance: InjectedWalletModule = {
7883
window.BinanceChain.on = (event, func) => {
7984
// intercept chainChanged event and format string
8085
if (event === 'chainChanged') {
81-
addListener(event, (chainId: string) => {
86+
addListener(event, (chainId: ChainId) => {
8287
const cb = func as ChainListener
83-
cb(`0x${parseInt(chainId).toString(16)}`)
88+
cb(`0x${parseInt(chainId as string).toString(16)}`)
8489
})
8590
} else {
8691
addListener(event, func)
8792
}
8893
}
8994

9095
const provider = createEIP1193Provider(window.BinanceChain, {
91-
// If the wallet is unlocked then we don't need to patch this request
92-
...(!window.BinanceChain.isUnlocked && {
93-
eth_accounts: () => Promise.resolve([])
94-
}),
95-
eth_requestAccounts: ({ baseRequest }) =>
96-
baseRequest({ method: 'eth_requestAccounts' }).then(accts => {
97-
window.BinanceChain.isUnlocked = true
98-
return accts
99-
}),
100-
eth_selectAccounts: UNSUPPORTED_METHOD,
10196
eth_chainId: ({ baseRequest }) =>
102-
baseRequest({ method: 'eth_chainId' }).then(
103-
id => `0x${parseInt(id).toString(16)}`
104-
),
97+
baseRequest({ method: 'eth_chainId' }).then(id => {
98+
return `0x${parseInt(id as string).toString(16)}`
99+
}),
105100
// Unsupported method -- will throw error
101+
eth_selectAccounts: UNSUPPORTED_METHOD,
106102
wallet_switchEthereumChain: UNSUPPORTED_METHOD
107103
})
108104

0 commit comments

Comments
 (0)