From 48c8e8b8d772ef05f10c00aa816b8acd2a17bf5d Mon Sep 17 00:00:00 2001 From: Brian Friel Date: Tue, 15 Nov 2022 12:52:24 -0800 Subject: [PATCH 01/12] feat: add Phantom injected provider --- packages/injected/src/icons/phantom.ts | 32 ++++++++++++++++++++++++++ packages/injected/src/types.ts | 6 +++-- packages/injected/src/wallets.ts | 13 ++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 packages/injected/src/icons/phantom.ts diff --git a/packages/injected/src/icons/phantom.ts b/packages/injected/src/icons/phantom.ts new file mode 100644 index 000000000..48a6946bb --- /dev/null +++ b/packages/injected/src/icons/phantom.ts @@ -0,0 +1,32 @@ +export default ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +` diff --git a/packages/injected/src/types.ts b/packages/injected/src/types.ts index f12098925..41bee93f0 100644 --- a/packages/injected/src/types.ts +++ b/packages/injected/src/types.ts @@ -49,7 +49,8 @@ export enum ProviderIdentityFlag { Core = 'isAvalanche', Opera = 'isOpera', Bitski = 'isBitski', - Enkrypt = 'isEnkrypt' + Enkrypt = 'isEnkrypt', + Phantom = 'isPhantom' } export enum ProviderLabel { @@ -89,7 +90,8 @@ export enum ProviderLabel { BitKeep = 'BitKeep', Sequence = 'Sequence', Core = 'Core', - Enkrypt = 'Enkrypt' + Enkrypt = 'Enkrypt', + Phantom = 'Phantom' } export interface MeetOneProvider extends ExternalProvider { diff --git a/packages/injected/src/wallets.ts b/packages/injected/src/wallets.ts index d470a77dc..9d1f9b43a 100644 --- a/packages/injected/src/wallets.ts +++ b/packages/injected/src/wallets.ts @@ -618,6 +618,16 @@ const enkrypt: InjectedWalletModule = { platforms: ['all'] } +const phantom: InjectedWalletModule = { + label: ProviderLabel.Phantom, + injectedNamespace: InjectedNameSpace.Ethereum, + checkProviderIdentity: ({ provider }) => + !!provider && !!provider[ProviderIdentityFlag.Phantom], + getIcon: async () => (await import('./icons/phantom.js')).default, + getInterface: getInjectedInterface(ProviderIdentityFlag.Phantom, true), + platforms: ['all'] +} + const wallets = [ exodus, metamask, @@ -653,7 +663,8 @@ const wallets = [ sequence, core, bitski, - enkrypt + enkrypt, + phantom ] export default wallets From 04978ef5d7656f486f59a79093253d68793829e6 Mon Sep 17 00:00:00 2001 From: Brian Friel Date: Thu, 17 Nov 2022 14:19:18 -0800 Subject: [PATCH 02/12] feat: add phantom package --- packages/demo/src/App.svelte | 5 ++- packages/injected/src/types.ts | 7 +++- packages/injected/src/wallets.ts | 2 +- packages/phantom/README.md | 30 +++++++++++++++ packages/phantom/package.json | 64 ++++++++++++++++++++++++++++++++ packages/phantom/src/icon.ts | 32 ++++++++++++++++ packages/phantom/src/index.ts | 30 +++++++++++++++ packages/phantom/tsconfig.json | 16 ++++++++ 8 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 packages/phantom/README.md create mode 100644 packages/phantom/package.json create mode 100644 packages/phantom/src/icon.ts create mode 100644 packages/phantom/src/index.ts create mode 100644 packages/phantom/tsconfig.json diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index 57c08cfec..1bc7c8e76 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -20,6 +20,7 @@ import enkryptModule from '@web3-onboard/enkrypt' import mewWalletModule from '@web3-onboard/mew-wallet' import uauthModule from '@web3-onboard/uauth' + import phantomModule from '@web3-onboard/phantom' import { recoverAddress, arrayify, @@ -93,6 +94,7 @@ const keystone = keystoneModule() const gnosis = gnosisModule() const tallyho = tallyHoModule() + const phantom = phantomModule() const trezorOptions = { email: 'test@test.com', @@ -142,7 +144,8 @@ dcent, sequence, tallyho, - uauth + uauth, + phantom ], gas, chains: [ diff --git a/packages/injected/src/types.ts b/packages/injected/src/types.ts index 41bee93f0..8a99b2b7e 100644 --- a/packages/injected/src/types.ts +++ b/packages/injected/src/types.ts @@ -115,7 +115,8 @@ export enum InjectedNameSpace { BitKeep = 'bitkeep', Avalanche = 'avalanche', Bitski = 'Bitski', - Enkrypt = 'enkrypt' + Enkrypt = 'enkrypt', + Phantom = 'phantom' } export interface CustomWindow extends Window { @@ -140,6 +141,10 @@ export interface CustomWindow extends Window { ethereum: InjectedProvider } } + phantom: { + ethereum: InjectedProvider + solana: any + } } export type InjectedProvider = ExternalProvider & diff --git a/packages/injected/src/wallets.ts b/packages/injected/src/wallets.ts index 9d1f9b43a..c4ac71f15 100644 --- a/packages/injected/src/wallets.ts +++ b/packages/injected/src/wallets.ts @@ -624,7 +624,7 @@ const phantom: InjectedWalletModule = { checkProviderIdentity: ({ provider }) => !!provider && !!provider[ProviderIdentityFlag.Phantom], getIcon: async () => (await import('./icons/phantom.js')).default, - getInterface: getInjectedInterface(ProviderIdentityFlag.Phantom, true), + getInterface: getInjectedInterface(ProviderIdentityFlag.Phantom), platforms: ['all'] } diff --git a/packages/phantom/README.md b/packages/phantom/README.md new file mode 100644 index 000000000..b3740d347 --- /dev/null +++ b/packages/phantom/README.md @@ -0,0 +1,30 @@ +# @web3-onboard/phantom + +## Wallet module for connecting Phantom to Web3-Onboard + +[Web3-Onboard](https://onboard.blocknative.com/) is an open-source, framework-agnostic JavaScript library to onboard users to web3 apps. This package can be used to integrate [Phantom](https://phantom.app/) into Web3-Onboard's "Connect Wallet" modal. For more information on Phantom, please refer to the [Phantom developer docs](https://docs.phantom.app/). + +### Install + +`npm i @web3-onboard/phantom` + +## Usage + +```typescript +import Onboard from '@web3-onboard/core' +import phantomModule from '@web3-onboard/phantom' + +// initialize the module with options +const phantom = phantomModule() + +const onboard = Onboard({ + // ... other Onboard options + wallets: [ + phantom + //... other wallets + ] +}) + +const connectedWallets = await onboard.connectWallet() +console.log(connectedWallets) +``` diff --git a/packages/phantom/package.json b/packages/phantom/package.json new file mode 100644 index 000000000..dbb5f5e66 --- /dev/null +++ b/packages/phantom/package.json @@ -0,0 +1,64 @@ +{ + "name": "@web3-onboard/phantom", + "version": "2.0.1-alpha.1", + "description": "Phantom 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.", + "keywords": [ + "Ethereum", + "Web3", + "EVM", + "dapp", + "Multichain", + "Wallet", + "Transaction", + "Provider", + "Hardware Wallet", + "Notifications", + "React", + "Svelte", + "Vue", + "Next", + "Nuxt", + "MetaMask", + "Coinbase", + "WalletConnect", + "Ledger", + "Trezor", + "Connect Wallet", + "Ethereum Hooks", + "Blocknative", + "Mempool", + "pending", + "confirmed", + "Injected Wallet", + "Crypto", + "Crypto Wallet", + "Phantom" + ], + "repository": { + "type": "git", + "url": "https://github.com/blocknative/web3-onboard.git", + "directory": "packages/core" + }, + "homepage": "https://onboard.blocknative.com", + "bugs": "https://github.com/blocknative/web3-onboard/issues", + "module": "dist/index.js", + "browser": "dist/index.js", + "main": "dist/index.js", + "type": "module", + "typings": "dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "tsc", + "dev": "tsc -w", + "type-check": "tsc --noEmit" + }, + "license": "MIT", + "devDependencies": { + "typescript": "^4.5.5" + }, + "dependencies": { + "@web3-onboard/common": "^2.2.3" + } +} diff --git a/packages/phantom/src/icon.ts b/packages/phantom/src/icon.ts new file mode 100644 index 000000000..48a6946bb --- /dev/null +++ b/packages/phantom/src/icon.ts @@ -0,0 +1,32 @@ +export default ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +` diff --git a/packages/phantom/src/index.ts b/packages/phantom/src/index.ts new file mode 100644 index 000000000..ca1f093b0 --- /dev/null +++ b/packages/phantom/src/index.ts @@ -0,0 +1,30 @@ +import { WalletInit } from '@web3-onboard/common' + +function phantom(): WalletInit { + if (typeof window === 'undefined') return () => null + return () => { + return { + label: 'Phantom', + injectedNamespace: 'phantom', + checkProviderIdentity: ({ provider }: { provider: any }) => { + !!provider && !!provider['isPhantom'] + }, + getIcon: async () => (await import('./icon.js')).default, + getInterface: async () => { + if ('phantom' in window) { + const anyWindow: any = window + const provider = anyWindow.phantom?.ethereum + + if (provider && provider.isPhantom) { + return { provider } + } + } + window.open('https://phantom.app/download', '_blank') + throw new Error('Please install Phantom before proceeding') + }, + platforms: ['all'] + } + } +} + +export default phantom diff --git a/packages/phantom/tsconfig.json b/packages/phantom/tsconfig.json new file mode 100644 index 000000000..53a27ffad --- /dev/null +++ b/packages/phantom/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"], + + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "declaration": true, + "declarationDir": "dist", + "allowSyntheticDefaultImports": true, + "paths": { + "*": ["./src/*", "./node_modules/*"] + }, + "typeRoots": ["node_modules/@types"] + } + } \ No newline at end of file From f48bf6cbd8077ee4a64b53441d94353622b3003e Mon Sep 17 00:00:00 2001 From: Brian Friel Date: Thu, 17 Nov 2022 14:45:36 -0800 Subject: [PATCH 03/12] chore: bump injected version number --- packages/injected/package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/injected/package.json b/packages/injected/package.json index 3ef89ba78..6d81b299f 100644 --- a/packages/injected/package.json +++ b/packages/injected/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/injected-wallets", - "version": "2.4.0-alpha.1", + "version": "2.4.0-alpha.2", "description": "Injected wallet module for connecting browser extension and mobile wallets 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.", "keywords": [ "Ethereum", @@ -30,7 +30,8 @@ "pending", "confirmed", "Injected Wallet", - "GameStop" + "GameStop", + "Phantom" ], "repository": { "type": "git", From 2136fa5a07476326b779a0481597233cee5bdc57 Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Mon, 21 Nov 2022 12:12:17 -0700 Subject: [PATCH 04/12] Bump version after merging in develop --- packages/demo/package.json | 2 +- packages/injected/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/demo/package.json b/packages/demo/package.json index cb2dd6187..9cd4094ab 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -28,7 +28,7 @@ "@web3-onboard/fortmatic": "^2.0.14", "@web3-onboard/gas": "^2.1.3", "@web3-onboard/gnosis": "^2.1.5", - "@web3-onboard/injected-wallets": "^2.4.0", + "@web3-onboard/injected-wallets": "^2.5.0-alpha.1", "@web3-onboard/keepkey": "^2.3.2", "@web3-onboard/keystone": "^2.3.2", "@web3-onboard/ledger": "^2.3.2", diff --git a/packages/injected/package.json b/packages/injected/package.json index 6d81b299f..322363106 100644 --- a/packages/injected/package.json +++ b/packages/injected/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/injected-wallets", - "version": "2.4.0-alpha.2", + "version": "2.5.0-alpha.1", "description": "Injected wallet module for connecting browser extension and mobile wallets 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.", "keywords": [ "Ethereum", From 60316df63753428e9daa607a8d2a5881d969eae4 Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Mon, 21 Nov 2022 12:13:47 -0700 Subject: [PATCH 05/12] Align phantom pkg versions --- packages/demo/package.json | 1 + packages/phantom/package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/demo/package.json b/packages/demo/package.json index 9cd4094ab..a85203daf 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -33,6 +33,7 @@ "@web3-onboard/keystone": "^2.3.2", "@web3-onboard/ledger": "^2.3.2", "@web3-onboard/magic": "^2.1.3", + "@web3-onboard/phantom": "^2.0.0-alpha.1", "@web3-onboard/portis": "^2.1.3", "@web3-onboard/sequence": "^2.0.3", "@web3-onboard/torus": "^2.1.3", diff --git a/packages/phantom/package.json b/packages/phantom/package.json index dbb5f5e66..4c217b770 100644 --- a/packages/phantom/package.json +++ b/packages/phantom/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/phantom", - "version": "2.0.1-alpha.1", + "version": "2.0.0-alpha.1", "description": "Phantom 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.", "keywords": [ "Ethereum", From 55a656360b0f550ccfa2fba68df84913c727c858 Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Mon, 21 Nov 2022 12:15:14 -0700 Subject: [PATCH 06/12] Add build steps for phantom --- .circleci/config.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index b71ccb054..eb75c974b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -327,6 +327,12 @@ jobs: working_directory: ~/web3-onboard-monorepo/packages/uauth steps: - node-build-steps + build-phantom: + docker: + - image: cimg/node:16.13.1 + working_directory: ~/web3-onboard-monorepo/packages/phantom + steps: + - node-build-steps # Build staging/Alpha releases build-staging-core: @@ -491,6 +497,12 @@ jobs: working_directory: ~/web3-onboard-monorepo/packages/uauth steps: - node-staging-build-steps + build-staging-phantom: + docker: + - image: cimg/node:16.13.1 + working_directory: ~/web3-onboard-monorepo/packages/phantom + steps: + - node-staging-build-steps workflows: version: 2 @@ -657,3 +669,9 @@ workflows: <<: *deploy_production_filters - build-staging-uauth: <<: *deploy_staging_filters + phantom: + jobs: + - build-phantom: + <<: *deploy_production_filters + - build-staging-phantom: + <<: *deploy_staging_filters From 380e56fca265cc2b565ff99cef6f249bf7e025bb Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Mon, 21 Nov 2022 12:18:27 -0700 Subject: [PATCH 07/12] Update readme and fix spelling errors --- packages/phantom/README.md | 6 +++--- packages/phantom/package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/phantom/README.md b/packages/phantom/README.md index b3740d347..57760da5d 100644 --- a/packages/phantom/README.md +++ b/packages/phantom/README.md @@ -2,11 +2,11 @@ ## Wallet module for connecting Phantom to Web3-Onboard -[Web3-Onboard](https://onboard.blocknative.com/) is an open-source, framework-agnostic JavaScript library to onboard users to web3 apps. This package can be used to integrate [Phantom](https://phantom.app/) into Web3-Onboard's "Connect Wallet" modal. For more information on Phantom, please refer to the [Phantom developer docs](https://docs.phantom.app/). +[Web3-Onboard](https://onboard.blocknative.com/) is an open-source, framework-agnostic JavaScript library to onboard users to web3 apps. This package can be used to integrate [Phantom Wallet](https://phantom.app/) support into Web3-Onboard's "Connect Wallet" modal. For more information on Phantom, please refer to the [Phantom developer docs](https://docs.phantom.app/). ### Install -`npm i @web3-onboard/phantom` +`npm i @web3-onboard/core @web3-onboard/phantom` ## Usage @@ -14,7 +14,7 @@ import Onboard from '@web3-onboard/core' import phantomModule from '@web3-onboard/phantom' -// initialize the module with options +// initialize the module const phantom = phantomModule() const onboard = Onboard({ diff --git a/packages/phantom/package.json b/packages/phantom/package.json index 4c217b770..a49ce7e67 100644 --- a/packages/phantom/package.json +++ b/packages/phantom/package.json @@ -1,7 +1,7 @@ { "name": "@web3-onboard/phantom", "version": "2.0.0-alpha.1", - "description": "Phantom 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.", + "description": "Phantom wallet module for connecting to Web3-Onboard. 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.", "keywords": [ "Ethereum", "Web3", From 6a177c3b563f40544e00830380ee852e8d7b336c Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Mon, 21 Nov 2022 12:29:38 -0700 Subject: [PATCH 08/12] Update Phantom package, update injected namespace within phantom injected-wallets --- packages/injected/src/wallets.ts | 2 +- packages/phantom/src/index.ts | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/injected/src/wallets.ts b/packages/injected/src/wallets.ts index c4ac71f15..81d14f7cf 100644 --- a/packages/injected/src/wallets.ts +++ b/packages/injected/src/wallets.ts @@ -620,7 +620,7 @@ const enkrypt: InjectedWalletModule = { const phantom: InjectedWalletModule = { label: ProviderLabel.Phantom, - injectedNamespace: InjectedNameSpace.Ethereum, + injectedNamespace: InjectedNameSpace.Phantom, checkProviderIdentity: ({ provider }) => !!provider && !!provider[ProviderIdentityFlag.Phantom], getIcon: async () => (await import('./icons/phantom.js')).default, diff --git a/packages/phantom/src/index.ts b/packages/phantom/src/index.ts index ca1f093b0..9f72a76ed 100644 --- a/packages/phantom/src/index.ts +++ b/packages/phantom/src/index.ts @@ -5,10 +5,6 @@ function phantom(): WalletInit { return () => { return { label: 'Phantom', - injectedNamespace: 'phantom', - checkProviderIdentity: ({ provider }: { provider: any }) => { - !!provider && !!provider['isPhantom'] - }, getIcon: async () => (await import('./icon.js')).default, getInterface: async () => { if ('phantom' in window) { From a30202982a7d6a2ff31e6c6139d32ede027f37ab Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Mon, 5 Dec 2022 12:07:15 -0700 Subject: [PATCH 09/12] Fix conflicts, add note to readme, yarn-it --- packages/phantom/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/phantom/README.md b/packages/phantom/README.md index 57760da5d..64d376ee7 100644 --- a/packages/phantom/README.md +++ b/packages/phantom/README.md @@ -2,7 +2,7 @@ ## Wallet module for connecting Phantom to Web3-Onboard -[Web3-Onboard](https://onboard.blocknative.com/) is an open-source, framework-agnostic JavaScript library to onboard users to web3 apps. This package can be used to integrate [Phantom Wallet](https://phantom.app/) support into Web3-Onboard's "Connect Wallet" modal. For more information on Phantom, please refer to the [Phantom developer docs](https://docs.phantom.app/). +[Web3-Onboard](https://onboard.blocknative.com/) is an open-source, framework-agnostic JavaScript library to onboard users to web3 apps. This package can be used to integrate [Phantom Wallet](https://phantom.app/) support into Web3-Onboard's "Connect Wallet" modal. With this module the Phantom option will be shown even if the extension is not installed on the users browser or used within the Phantom app. If selected the user will be taken to a download screen and prompted to create a Phantom wallet. For more information on Phantom, please refer to the [Phantom developer docs](https://docs.phantom.app/). ### Install From 8f25f0fbde7d3b1b494f01049a13d199dd0c4138 Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Mon, 5 Dec 2022 12:37:02 -0700 Subject: [PATCH 10/12] Create provider properly, remove conditional chaining for build across oldercompilers --- packages/injected/src/types.ts | 1 - packages/injected/src/wallets.ts | 6 ++++-- packages/phantom/src/index.ts | 13 +++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/injected/src/types.ts b/packages/injected/src/types.ts index 8a99b2b7e..ba96849fc 100644 --- a/packages/injected/src/types.ts +++ b/packages/injected/src/types.ts @@ -143,7 +143,6 @@ export interface CustomWindow extends Window { } phantom: { ethereum: InjectedProvider - solana: any } } diff --git a/packages/injected/src/wallets.ts b/packages/injected/src/wallets.ts index 81d14f7cf..cdd69568c 100644 --- a/packages/injected/src/wallets.ts +++ b/packages/injected/src/wallets.ts @@ -622,9 +622,11 @@ const phantom: InjectedWalletModule = { label: ProviderLabel.Phantom, injectedNamespace: InjectedNameSpace.Phantom, checkProviderIdentity: ({ provider }) => - !!provider && !!provider[ProviderIdentityFlag.Phantom], + !!provider && !!provider['ethereum'][ProviderIdentityFlag.Phantom], getIcon: async () => (await import('./icons/phantom.js')).default, - getInterface: getInjectedInterface(ProviderIdentityFlag.Phantom), + getInterface: async () => ({ + provider: createEIP1193Provider(window.phantom.ethereum) + }), platforms: ['all'] } diff --git a/packages/phantom/src/index.ts b/packages/phantom/src/index.ts index 9f72a76ed..542b0d2f7 100644 --- a/packages/phantom/src/index.ts +++ b/packages/phantom/src/index.ts @@ -1,4 +1,4 @@ -import { WalletInit } from '@web3-onboard/common' +import { WalletInit, createEIP1193Provider } from '@web3-onboard/common' function phantom(): WalletInit { if (typeof window === 'undefined') return () => null @@ -9,10 +9,15 @@ function phantom(): WalletInit { getInterface: async () => { if ('phantom' in window) { const anyWindow: any = window - const provider = anyWindow.phantom?.ethereum - if (provider && provider.isPhantom) { - return { provider } + if ( + 'phantom' in anyWindow && + 'ethereum' in anyWindow.phantom && + anyWindow.phantom.ethereum.isPhantom + ) { + return { + provider: createEIP1193Provider(anyWindow.phantom.ethereum) + } } } window.open('https://phantom.app/download', '_blank') From b8b44a8c3a2b8a4151e76b3f46083e021e0b7d92 Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Tue, 20 Dec 2022 12:43:59 -0700 Subject: [PATCH 11/12] Add check for ethereum prop within phantom provider --- packages/demo/src/App.svelte | 2 +- packages/injected/src/wallets.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index 4725da3e3..b90622885 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -147,7 +147,7 @@ sequence, tallyho, uauth, - phantom + // phantom ], transactionPreview, gas, diff --git a/packages/injected/src/wallets.ts b/packages/injected/src/wallets.ts index cdd69568c..397e1f42f 100644 --- a/packages/injected/src/wallets.ts +++ b/packages/injected/src/wallets.ts @@ -622,7 +622,9 @@ const phantom: InjectedWalletModule = { label: ProviderLabel.Phantom, injectedNamespace: InjectedNameSpace.Phantom, checkProviderIdentity: ({ provider }) => - !!provider && !!provider['ethereum'][ProviderIdentityFlag.Phantom], + !!provider && + !!provider['ethereum'] && + !!provider['ethereum'][ProviderIdentityFlag.Phantom], getIcon: async () => (await import('./icons/phantom.js')).default, getInterface: async () => ({ provider: createEIP1193Provider(window.phantom.ethereum) From f4747f7b8f6bd414c39c69bfa2b5919cbb39174c Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Tue, 20 Dec 2022 12:52:04 -0700 Subject: [PATCH 12/12] Return phantom to demo --- packages/demo/src/App.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index b90622885..4725da3e3 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -147,7 +147,7 @@ sequence, tallyho, uauth, - // phantom + phantom ], transactionPreview, gas,