From dafa7926842ac43909f74e8dca057bd23a78a54e Mon Sep 17 00:00:00 2001 From: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Date: Sat, 29 Jul 2023 00:29:38 +0800 Subject: [PATCH] feat: add coinbase provider (#10202) * chore: add coinbase provider * refactor: remove WalletLink * refactor: remove MathWallet * refactor: code style * chore: coinbase switch chain * chore: update chain list * refactor: code style --- .../main/GlobalVariableBridge/index.ts | 6 +- packages/injected-script/sdk/Base.ts | 13 +-- packages/injected-script/sdk/Clover.ts | 5 +- packages/injected-script/sdk/Coin98.ts | 4 +- packages/injected-script/sdk/Coinbase.ts | 24 ++++++ packages/injected-script/sdk/MathWallet.ts | 11 --- packages/injected-script/sdk/MetaMask.ts | 6 +- packages/injected-script/sdk/Opera.ts | 5 +- packages/injected-script/sdk/Phantom.ts | 4 +- packages/injected-script/sdk/Solflare.ts | 3 +- packages/injected-script/sdk/WalletLink.ts | 12 --- packages/injected-script/sdk/index.ts | 30 ++++--- packages/injected-script/sdk/tsconfig.json | 3 +- .../components/ConnectionContent.tsx | 8 ++ .../src/Web3/Base/state/Provider.ts | 84 ++++++++++--------- .../src/Web3/EVM/middleware/Interceptor.ts | 2 - .../src/Web3/EVM/providers/Base.ts | 12 ++- .../Web3/EVM/providers/BaseContractWallet.ts | 8 -- .../src/Web3/EVM/providers/BaseHosted.ts | 16 ---- .../src/Web3/EVM/providers/BaseInjected.ts | 2 +- .../providers/{MathWallet.ts => Coinbase.ts} | 6 +- .../src/Web3/EVM/providers/MaskWallet.ts | 1 + .../src/Web3/EVM/providers/MetaMask.ts | 6 +- .../src/Web3/EVM/providers/Opera.ts | 4 +- .../src/Web3/EVM/providers/WalletLink.ts | 13 --- .../src/Web3/EVM/providers/index.ts | 6 +- .../src/Web3/Solana/providers/BaseInjected.ts | 4 +- .../src/helpers/fetchJsonRpcResponse.ts | 8 -- .../evm/src/constants/descriptors.ts | 29 ++----- packages/web3-shared/evm/src/types/index.ts | 3 +- 30 files changed, 150 insertions(+), 188 deletions(-) create mode 100644 packages/injected-script/sdk/Coinbase.ts delete mode 100644 packages/injected-script/sdk/MathWallet.ts delete mode 100644 packages/injected-script/sdk/WalletLink.ts rename packages/web3-providers/src/Web3/EVM/providers/{MathWallet.ts => Coinbase.ts} (67%) delete mode 100644 packages/web3-providers/src/Web3/EVM/providers/WalletLink.ts diff --git a/packages/injected-script/main/GlobalVariableBridge/index.ts b/packages/injected-script/main/GlobalVariableBridge/index.ts index c0a9d1d592b6..387dc1a21304 100644 --- a/packages/injected-script/main/GlobalVariableBridge/index.ts +++ b/packages/injected-script/main/GlobalVariableBridge/index.ts @@ -80,12 +80,12 @@ export function __unsafe__onEvent(path: string, bridgeEvent: keyof InternalEvent function __unsafe__untilInner(name: string) { if ($.hasOwn(__unsafe__window, name)) return $.PromiseResolve(true) - let restCheckTimes = 150 // 30s + let restCheckTimes = 15 // 3s - return new $.Promise((resolve) => { + return new $.Promise((resolve, reject) => { function check() { restCheckTimes -= 1 - if (restCheckTimes < 0) return + if (restCheckTimes < 0) return reject(new Error('timeout')) if ($.hasOwn(__unsafe__window, name)) return resolve(true) $.setTimeout(check, 200) } diff --git a/packages/injected-script/sdk/Base.ts b/packages/injected-script/sdk/Base.ts index b1f8bc3bfacf..cbd6d96fa576 100644 --- a/packages/injected-script/sdk/Base.ts +++ b/packages/injected-script/sdk/Base.ts @@ -1,9 +1,9 @@ import { createPromise, sendEvent } from './utils.js' export class InjectedProvider { - private events = new Map void>>() - private isReadyInternal = false - private isConnectedInternal = false + protected events = new Map void>>() + protected isReadyInternal = false + protected isConnectedInternal = false constructor(public pathname: string) { this.startup() @@ -12,6 +12,9 @@ export class InjectedProvider { private async startup() { await this.untilAvailable() + // if a provider is not ready, it will not be able to connect + if (!this.isReady) return + this.on('connected', () => { this.isConnectedInternal = true }) @@ -19,7 +22,7 @@ export class InjectedProvider { this.isConnectedInternal = false }) - this.isConnectedInternal = (await this.getProperty('isConnected')) as boolean + this.isConnectedInternal = (await this.getProperty('isConnected')) ?? false } get isReady() { @@ -95,7 +98,7 @@ export class InjectedProvider { /** * Access primitive property on the sdk object. */ - getProperty(key: string): Promise { + getProperty(key: string): Promise { return createPromise((id) => sendEvent('web3BridgePrimitiveAccess', this.pathname, id, key)) } } diff --git a/packages/injected-script/sdk/Clover.ts b/packages/injected-script/sdk/Clover.ts index 42d1bf827fe8..d7ee30a05937 100644 --- a/packages/injected-script/sdk/Clover.ts +++ b/packages/injected-script/sdk/Clover.ts @@ -6,6 +6,9 @@ export class CloverProvider extends InjectedProvider { } override async untilAvailable(): Promise { - await super.untilAvailable(() => super.getProperty('isClover') as Promise) + await super.untilAvailable(async () => { + const isClover = await super.getProperty('isClover') + return !!isClover + }) } } diff --git a/packages/injected-script/sdk/Coin98.ts b/packages/injected-script/sdk/Coin98.ts index 92ae9dbb74bf..02e30eedb0ec 100644 --- a/packages/injected-script/sdk/Coin98.ts +++ b/packages/injected-script/sdk/Coin98.ts @@ -20,9 +20,7 @@ export class Coin98Provider extends InjectedProvider { override async request(data: RequestArguments): Promise { // coin98 cannot handle it correctly (test with coin98 v6.0.3) - if (data.method === 'eth_chainId') { - return this.getProperty('chainId') as T - } + if (data.method === 'eth_chainId') return (await this.getProperty('chainId'))! return super.request(data) } } diff --git a/packages/injected-script/sdk/Coinbase.ts b/packages/injected-script/sdk/Coinbase.ts new file mode 100644 index 000000000000..89e659e10243 --- /dev/null +++ b/packages/injected-script/sdk/Coinbase.ts @@ -0,0 +1,24 @@ +import { InjectedProvider } from './Base.js' +import { createPromise, sendEvent } from './utils.js' + +export class CoinbaseProvider extends InjectedProvider { + constructor() { + super('coinbaseWalletExtension') + } + + override async untilAvailable(): Promise { + await super.untilAvailable(async () => !!(await super.getProperty('isCoinbaseWallet'))) + } + + override connect(options: unknown): Promise { + return createPromise((id) => sendEvent('web3BridgeExecute', [this.pathname, 'enable'].join('.'), id, options)) + } + + override emit(event: string, data: unknown[]) { + for (const f of this.events.get(event) || []) { + try { + Reflect.apply(f, null, event === 'chainChanged' ? [`0x${Number(data[0]).toString(16)}`] : data) + } catch {} + } + } +} diff --git a/packages/injected-script/sdk/MathWallet.ts b/packages/injected-script/sdk/MathWallet.ts deleted file mode 100644 index 0304fb4830a2..000000000000 --- a/packages/injected-script/sdk/MathWallet.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { InjectedProvider } from './Base.js' - -export class MathWalletProvider extends InjectedProvider { - constructor() { - super('ethereum') - } - - override async untilAvailable(): Promise { - await super.untilAvailable(() => super.getProperty('isMathWallet') as Promise) - } -} diff --git a/packages/injected-script/sdk/MetaMask.ts b/packages/injected-script/sdk/MetaMask.ts index 3721e9134c99..a691ed36cd92 100644 --- a/packages/injected-script/sdk/MetaMask.ts +++ b/packages/injected-script/sdk/MetaMask.ts @@ -6,6 +6,10 @@ export class MetaMaskProvider extends InjectedProvider { } override async untilAvailable(): Promise { - await super.untilAvailable(() => super.getProperty('isMetaMask') as Promise) + await super.untilAvailable(async () => { + const isMetaMask = await super.getProperty('isMetaMask') + const isCoinbaseWallet = await super.getProperty('isCoinbaseWallet') + return !!isMetaMask && !isCoinbaseWallet + }) } } diff --git a/packages/injected-script/sdk/Opera.ts b/packages/injected-script/sdk/Opera.ts index 0dc69b7a36c2..84179bb0f4b8 100644 --- a/packages/injected-script/sdk/Opera.ts +++ b/packages/injected-script/sdk/Opera.ts @@ -6,6 +6,9 @@ export class OperaProvider extends InjectedProvider { } override async untilAvailable(): Promise { - await super.untilAvailable(() => super.getProperty('isOpera') as Promise) + await super.untilAvailable(async () => { + const isOpera = await super.getProperty('isOpera') + return !!isOpera + }) } } diff --git a/packages/injected-script/sdk/Phantom.ts b/packages/injected-script/sdk/Phantom.ts index cdf26a73132d..5699dac1088a 100644 --- a/packages/injected-script/sdk/Phantom.ts +++ b/packages/injected-script/sdk/Phantom.ts @@ -4,11 +4,11 @@ export class PhantomProvider extends InjectedProvider { constructor() { super('phantom.solana') } + override async connect(options: unknown): Promise { await super.connect(options) - const publicKey = (await super.getProperty('publicKey')) as string return { - publicKey, + publicKey: await super.getProperty('publicKey'), } } } diff --git a/packages/injected-script/sdk/Solflare.ts b/packages/injected-script/sdk/Solflare.ts index 51ba16484f11..18be81e582e2 100644 --- a/packages/injected-script/sdk/Solflare.ts +++ b/packages/injected-script/sdk/Solflare.ts @@ -7,9 +7,8 @@ export class SolflareProvider extends InjectedProvider { override async connect(options: unknown): Promise { await super.connect(options) - const publicKey = (await super.getProperty('publicKey')) as string return { - publicKey, + publicKey: await super.getProperty('publicKey'), } } } diff --git a/packages/injected-script/sdk/WalletLink.ts b/packages/injected-script/sdk/WalletLink.ts deleted file mode 100644 index 3cb115619080..000000000000 --- a/packages/injected-script/sdk/WalletLink.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { InjectedProvider } from './Base.js' -import { createPromise, sendEvent } from './utils.js' - -export class WalletLinkProvider extends InjectedProvider { - constructor() { - super('walletLinkExtension') - } - - override connect(options: unknown): Promise { - return createPromise((id) => sendEvent('web3BridgeExecute', [this.pathname, 'enable'].join('.'), id, options)) - } -} diff --git a/packages/injected-script/sdk/index.ts b/packages/injected-script/sdk/index.ts index 9e5b57045cc9..697c3e81e885 100644 --- a/packages/injected-script/sdk/index.ts +++ b/packages/injected-script/sdk/index.ts @@ -1,11 +1,10 @@ import { CustomEventId, decodeEvent } from '../shared/index.js' import { Coin98Provider, Coin98ProviderType } from './Coin98.js' +import { CoinbaseProvider } from './Coinbase.js' import { PhantomProvider } from './Phantom.js' import { SolflareProvider } from './Solflare.js' import { MetaMaskProvider } from './MetaMask.js' import { sendEvent, rejectPromise, resolvePromise } from './utils.js' -import { MathWalletProvider } from './MathWallet.js' -import { WalletLinkProvider } from './WalletLink.js' import { OperaProvider } from './Opera.js' import { CloverProvider } from './Clover.js' @@ -17,11 +16,21 @@ export const injectedCoin98SolanaProvider = new Coin98Provider(Coin98ProviderTyp export const injectedPhantomProvider = new PhantomProvider() export const injectedSolflareProvider = new SolflareProvider() export const injectedMetaMaskProvider = new MetaMaskProvider() -export const injectedMathWalletProvider = new MathWalletProvider() -export const injectedWalletLinkProvider = new WalletLinkProvider() +export const injectedCoinbaseProvider = new CoinbaseProvider() export const injectedOperaProvider = new OperaProvider() export const injectedCloverProvider = new CloverProvider() +// Please keep this list update to date +const Providers = [ + injectedCoinbaseProvider, + injectedOperaProvider, + injectedCloverProvider, + injectedMetaMaskProvider, + injectedCoin98EVMProvider, + injectedCoin98SolanaProvider, + injectedPhantomProvider, +] + export function pasteText(text: string) { sendEvent('paste', text) } @@ -60,18 +69,7 @@ globalThis.document?.addEventListener?.(CustomEventId, (e) => { case 'web3BridgeEmitEvent': const [pathname, eventName, data] = r[1] - const provider = [ - injectedCoin98EVMProvider, - injectedCoin98SolanaProvider, - injectedPhantomProvider, - injectedMetaMaskProvider, - injectedMathWalletProvider, - injectedWalletLinkProvider, - injectedOperaProvider, - injectedCloverProvider, - ].find((x) => x.pathname === pathname) - - provider?.emit(eventName, data) + Providers.filter((x) => x.pathname === pathname).forEach((x) => x?.emit(eventName, data)) return case 'web3BridgeBindEvent': diff --git a/packages/injected-script/sdk/tsconfig.json b/packages/injected-script/sdk/tsconfig.json index 979ca9312545..d7f5a3059922 100644 --- a/packages/injected-script/sdk/tsconfig.json +++ b/packages/injected-script/sdk/tsconfig.json @@ -11,10 +11,9 @@ "Phantom.ts", "Solflare.ts", "Coin98.ts", + "Coinbase.ts", "MetaMask.ts", - "MathWallet.ts", "Opera.ts", - "WalletLink.ts", "Clover.ts", "utils.ts" ], diff --git a/packages/plugins/Debugger/src/SNSAdaptor/components/ConnectionContent.tsx b/packages/plugins/Debugger/src/SNSAdaptor/components/ConnectionContent.tsx index 5ce9a8497285..f9ee84ae22ea 100644 --- a/packages/plugins/Debugger/src/SNSAdaptor/components/ConnectionContent.tsx +++ b/packages/plugins/Debugger/src/SNSAdaptor/components/ConnectionContent.tsx @@ -242,6 +242,14 @@ export function ConnectionContent(props: ConnectionContentProps) { } catch (error: unknown) { // eslint-disable-next-line no-alert if (error instanceof Error) alert(error.message) + } finally { + if ((await Web3.getChainId()) === chainId) { + // eslint-disable-next-line no-alert + alert(`Switched to chain ${chainId}`) + } else { + // eslint-disable-next-line no-alert + alert(`Failed to switch to chain ${chainId}`) + } } }, []) diff --git a/packages/web3-providers/src/Web3/Base/state/Provider.ts b/packages/web3-providers/src/Web3/Base/state/Provider.ts index c627d91e7923..279c0bd40836 100644 --- a/packages/web3-providers/src/Web3/Base/state/Provider.ts +++ b/packages/web3-providers/src/Web3/Base/state/Provider.ts @@ -76,8 +76,7 @@ export class ProviderState< } async setup() { - await Promise.all([this.storage.account.initializedPromise, this.storage.providerType.initializedPromise]) - + await this.readyPromise await this.setupSubscriptions() await this.setupProviders() } @@ -100,52 +99,55 @@ export class ProviderState< } private async setupProviders() { - await Promise.all( - Object.entries(this.providers).map(async (entry) => { - const [providerType, provider] = entry as [ - ProviderType, - WalletAPI.Provider, - ] - - provider.emitter.on('chainId', async (chainId) => { - await this.setAccount(providerType, { - chainId: Number.parseInt(chainId, 16) as ChainId, - }) + const providers = Object.entries(this.providers) as Array< + [ProviderType, WalletAPI.Provider] + > + + providers.map(async ([providerType, provider]) => { + try { + await provider.readyPromise + if (!provider.ready) return + } catch { + return + } + + provider.emitter.on('chainId', async (chainId) => { + await this.setAccount(providerType, { + chainId: Number.parseInt(chainId, 16) as ChainId, }) - provider.emitter.on('connect', async ({ account }) => { - if (!this.options.isValidAddress(account)) return - // provider should update before account, otherwise account failed to update - await this.setProvider(providerType) - await this.setAccount(providerType, { - account, - }) + }) + provider.emitter.on('connect', async ({ account }) => { + if (!this.options.isValidAddress(account)) return + // provider should update before account, otherwise account failed to update + await this.setProvider(providerType) + await this.setAccount(providerType, { + account, }) - provider.emitter.on('accounts', async (accounts) => { - const account = first(accounts) + }) + provider.emitter.on('accounts', async (accounts) => { + const account = first(accounts) - if (account && this.options.isValidAddress(account)) - await this.setAccount(providerType, { - account, - }) - }) - provider.emitter.on('disconnect', async () => { + if (account && this.options.isValidAddress(account)) await this.setAccount(providerType, { - account: '', - chainId: this.options.getDefaultChainId(), + account, }) - - if (!this.site) return - - await this.storage.providerType.setValue(this.options.getDefaultProviderType()) + }) + provider.emitter.on('disconnect', async () => { + await this.setAccount(providerType, { + account: '', + chainId: this.options.getDefaultChainId(), }) - try { - await provider.setup(this.context) - } catch { - // ignore setup errors - } - }), - ) + if (!this.site) return + await this.storage.providerType.setValue(this.options.getDefaultProviderType()) + }) + + try { + await provider.setup(this.context) + } catch { + // ignore setup errors + } + }) } private async setAccount(providerType: ProviderType, account: Partial>) { diff --git a/packages/web3-providers/src/Web3/EVM/middleware/Interceptor.ts b/packages/web3-providers/src/Web3/EVM/middleware/Interceptor.ts index e01bfd31534f..6994c2230682 100644 --- a/packages/web3-providers/src/Web3/EVM/middleware/Interceptor.ts +++ b/packages/web3-providers/src/Web3/EVM/middleware/Interceptor.ts @@ -24,8 +24,6 @@ export class Interceptor implements Middleware { [ProviderType.MetaMask]: Composer.from(new MetaMaskLike(ProviderType.MetaMask)), [ProviderType.WalletConnect]: Composer.from(new WalletConnect()), [ProviderType.Coin98]: Composer.from(new MetaMaskLike(ProviderType.Coin98)), - [ProviderType.WalletLink]: Composer.from(new MetaMaskLike(ProviderType.WalletLink)), - [ProviderType.MathWallet]: Composer.from(new MetaMaskLike(ProviderType.MathWallet)), [ProviderType.Fortmatic]: Composer.from(new Fortmatic()), [ProviderType.Opera]: Composer.from(new MetaMaskLike(ProviderType.Opera)), [ProviderType.Clover]: Composer.from(new MetaMaskLike(ProviderType.Clover)), diff --git a/packages/web3-providers/src/Web3/EVM/providers/Base.ts b/packages/web3-providers/src/Web3/EVM/providers/Base.ts index ffaaf4345439..4a24a4ae3bf8 100644 --- a/packages/web3-providers/src/Web3/EVM/providers/Base.ts +++ b/packages/web3-providers/src/Web3/EVM/providers/Base.ts @@ -39,12 +39,20 @@ export class BaseProvider implements WalletAPI.Provider !!x) - } - - override get readyPromise() { - return Promise.all([super.readyPromise, this.ownerStorage?.initializedPromise]).then(() => {}) - } - get ownerAccount() { return this.ownerStorage?.value.account ?? this.options.getDefaultAccount() } diff --git a/packages/web3-providers/src/Web3/EVM/providers/BaseHosted.ts b/packages/web3-providers/src/Web3/EVM/providers/BaseHosted.ts index 5c342ff0ef9c..6a5420a16190 100644 --- a/packages/web3-providers/src/Web3/EVM/providers/BaseHosted.ts +++ b/packages/web3-providers/src/Web3/EVM/providers/BaseHosted.ts @@ -83,22 +83,6 @@ export class BaseHostedProvider } } - override get ready() { - return [ - this.walletStorage?.wallets.initialized, - this.walletStorage?.account.initialized, - this.walletStorage?.chainId.initialized, - ].every((x) => !!x) - } - - override get readyPromise() { - return Promise.all([ - this.walletStorage?.wallets.initializedPromise, - this.walletStorage?.account.initializedPromise, - this.walletStorage?.chainId.initializedPromise, - ]).then(() => {}) - } - override get subscription() { if (!this.walletStorage) return super.subscription return { diff --git a/packages/web3-providers/src/Web3/EVM/providers/BaseInjected.ts b/packages/web3-providers/src/Web3/EVM/providers/BaseInjected.ts index 0e1e06afae4c..3b1ed94b5c08 100644 --- a/packages/web3-providers/src/Web3/EVM/providers/BaseInjected.ts +++ b/packages/web3-providers/src/Web3/EVM/providers/BaseInjected.ts @@ -29,7 +29,7 @@ export class BaseInjectedProvider } override get readyPromise() { - if (isInPageEthereumInjected()) return this.bridge.untilAvailable().then(() => undefined) + if (isInPageEthereumInjected()) return this.bridge.untilAvailable() return Promise.reject(new Error('Not available on extension site.')) } diff --git a/packages/web3-providers/src/Web3/EVM/providers/MathWallet.ts b/packages/web3-providers/src/Web3/EVM/providers/Coinbase.ts similarity index 67% rename from packages/web3-providers/src/Web3/EVM/providers/MathWallet.ts rename to packages/web3-providers/src/Web3/EVM/providers/Coinbase.ts index ff34289b6cc2..dc9e19239a43 100644 --- a/packages/web3-providers/src/Web3/EVM/providers/MathWallet.ts +++ b/packages/web3-providers/src/Web3/EVM/providers/Coinbase.ts @@ -1,13 +1,13 @@ -import { injectedMathWalletProvider } from '@masknet/injected-script' +import { injectedCoinbaseProvider } from '@masknet/injected-script' import { type ChainId, ProviderType, type Web3, type Web3Provider } from '@masknet/web3-shared-evm' import { BaseInjectedProvider } from './BaseInjected.js' import type { WalletAPI } from '../../../entry-types.js' -export class MathWalletProvider +export class CoinbaseProvider extends BaseInjectedProvider implements WalletAPI.Provider { constructor() { - super(ProviderType.MathWallet, injectedMathWalletProvider) + super(ProviderType.Coinbase, injectedCoinbaseProvider) } } diff --git a/packages/web3-providers/src/Web3/EVM/providers/MaskWallet.ts b/packages/web3-providers/src/Web3/EVM/providers/MaskWallet.ts index 7c42a6d19802..fa08f02cca9a 100644 --- a/packages/web3-providers/src/Web3/EVM/providers/MaskWallet.ts +++ b/packages/web3-providers/src/Web3/EVM/providers/MaskWallet.ts @@ -46,6 +46,7 @@ export class MaskWalletProvider (x) => !!x.owner, ) } + async update() { // Fetching info of SmartPay wallets is slow, update provider wallets eagerly here. await this.updateImmediately() diff --git a/packages/web3-providers/src/Web3/EVM/providers/MetaMask.ts b/packages/web3-providers/src/Web3/EVM/providers/MetaMask.ts index cef96d095a2c..d2dd9ab22fb0 100644 --- a/packages/web3-providers/src/Web3/EVM/providers/MetaMask.ts +++ b/packages/web3-providers/src/Web3/EVM/providers/MetaMask.ts @@ -26,15 +26,13 @@ export class MetaMaskProvider } override get ready() { - if (isEthereumInjected()) return true - if (isInPageEthereumInjected()) return super.ready + if (isEthereumInjected() || isInPageEthereumInjected()) return super.ready const isConnected = (this.bridge as unknown as MetaMaskInpageProvider).isConnected() return isConnected } override get readyPromise() { - if (isEthereumInjected()) return Promise.resolve(undefined) - if (isInPageEthereumInjected()) return super.readyPromise + if (isEthereumInjected() || isInPageEthereumInjected()) return super.readyPromise return Promise.resolve(undefined) } diff --git a/packages/web3-providers/src/Web3/EVM/providers/Opera.ts b/packages/web3-providers/src/Web3/EVM/providers/Opera.ts index d593f0732142..c403dee8aeea 100644 --- a/packages/web3-providers/src/Web3/EVM/providers/Opera.ts +++ b/packages/web3-providers/src/Web3/EVM/providers/Opera.ts @@ -21,12 +21,12 @@ export class OperaProvider } override get ready() { - if (!Sniffings.is_opera) return true + if (Sniffings.is_opera) return true return super.ready } override get readyPromise() { - if (!Sniffings.is_opera) return Promise.resolve(undefined) + if (Sniffings.is_opera) return Promise.resolve() return super.readyPromise } diff --git a/packages/web3-providers/src/Web3/EVM/providers/WalletLink.ts b/packages/web3-providers/src/Web3/EVM/providers/WalletLink.ts deleted file mode 100644 index fe4f13d3c3b6..000000000000 --- a/packages/web3-providers/src/Web3/EVM/providers/WalletLink.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { injectedWalletLinkProvider } from '@masknet/injected-script' -import { type ChainId, ProviderType, type Web3, type Web3Provider } from '@masknet/web3-shared-evm' -import { BaseInjectedProvider } from './BaseInjected.js' -import type { WalletAPI } from '../../../entry-types.js' - -export class WalletLinkProvider - extends BaseInjectedProvider - implements WalletAPI.Provider -{ - constructor() { - super(ProviderType.WalletLink, injectedWalletLinkProvider) - } -} diff --git a/packages/web3-providers/src/Web3/EVM/providers/index.ts b/packages/web3-providers/src/Web3/EVM/providers/index.ts index 0e9d8c45dfc4..c151255da2c1 100644 --- a/packages/web3-providers/src/Web3/EVM/providers/index.ts +++ b/packages/web3-providers/src/Web3/EVM/providers/index.ts @@ -4,8 +4,7 @@ import { MetaMaskProvider } from './MetaMask.js' import WalletConnectProvider from './WalletConnect.js' import WalletConnectV2Provider from './WalletConnectV2.js' import { EVM_Coin98Provider } from './Coin98.js' -import { WalletLinkProvider } from './WalletLink.js' -import { MathWalletProvider } from './MathWallet.js' +import { CoinbaseProvider } from './Coinbase.js' import { CloverProvider } from './Clover.js' import FortmaticProvider from './Fortmatic.js' import { OperaProvider } from './Opera.js' @@ -22,8 +21,7 @@ export const Providers: Record = { [ProviderType.WalletConnect]: new WalletConnectProvider(), [ProviderType.WalletConnectV2]: new WalletConnectV2Provider(), [ProviderType.Coin98]: new EVM_Coin98Provider(), - [ProviderType.WalletLink]: new WalletLinkProvider(), - [ProviderType.MathWallet]: new MathWalletProvider(), + [ProviderType.Coinbase]: new CoinbaseProvider(), [ProviderType.Clover]: new CloverProvider(), [ProviderType.Fortmatic]: new FortmaticProvider(), [ProviderType.Opera]: new OperaProvider(), diff --git a/packages/web3-providers/src/Web3/Solana/providers/BaseInjected.ts b/packages/web3-providers/src/Web3/Solana/providers/BaseInjected.ts index abb097157d0b..458696cbaae5 100644 --- a/packages/web3-providers/src/Web3/Solana/providers/BaseInjected.ts +++ b/packages/web3-providers/src/Web3/Solana/providers/BaseInjected.ts @@ -20,8 +20,8 @@ export class BaseInjectedProvider } override get readyPromise() { - if (isExtensionSiteType()) return Promise.reject(new Error('Not available on extension site.')) - return this.bridge.untilAvailable().then(() => undefined) + if (!isExtensionSiteType()) return this.bridge.untilAvailable() + return Promise.reject(new Error('Not available on extension site.')) } override async setup(): Promise { diff --git a/packages/web3-providers/src/helpers/fetchJsonRpcResponse.ts b/packages/web3-providers/src/helpers/fetchJsonRpcResponse.ts index 9f954258e6f5..9847b1ecf672 100644 --- a/packages/web3-providers/src/helpers/fetchJsonRpcResponse.ts +++ b/packages/web3-providers/src/helpers/fetchJsonRpcResponse.ts @@ -5,14 +5,6 @@ import { fetchSquashedJSON } from './fetchJSON.js' async function resolveRequestKey(request: Request) { try { const body: JsonRpcPayload = await request.json() - - console.log('DEBUG: resolveRequestKey') - console.log({ - ID: RequestID.fromPayload(request.url, body).ID, - url: request.url, - body, - }) - return RequestID.fromPayload(request.url, body).ID ?? '' } catch { return '' diff --git a/packages/web3-shared/evm/src/constants/descriptors.ts b/packages/web3-shared/evm/src/constants/descriptors.ts index 2b475a373457..4213696fa596 100644 --- a/packages/web3-shared/evm/src/constants/descriptors.ts +++ b/packages/web3-shared/evm/src/constants/descriptors.ts @@ -379,32 +379,19 @@ export const PROVIDER_DESCRIPTORS: Array