diff --git a/package.json b/package.json index d53cd8120..34fd4a94e 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,7 @@ "tailwindcss": "^3.3.2", "tippy.js": "^6.3.7", "trezor-connect": "^8.1.29", + "uuid": "^9.0.1", "webext-redux": "^2.1.7", "webextension-polyfill": "^0.8.0", "webextension-polyfill-ts": "^0.25.0", @@ -134,6 +135,7 @@ "@types/react": "^18.2.5", "@types/react-dom": "^18.2.3", "@types/selenium-webdriver": "^4.1.14", + "@types/uuid": "^9.0.7", "@types/webpack": "^5.28.1", "@typescript-eslint/parser": "^5.10.2", "babel-loader": "^9.1.2", diff --git a/source/scripts/ContentScript/inject/inpage.ts b/source/scripts/ContentScript/inject/inpage.ts index a3e3045b3..d0168ebda 100644 --- a/source/scripts/ContentScript/inject/inpage.ts +++ b/source/scripts/ContentScript/inject/inpage.ts @@ -1,5 +1,9 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import { v4 as uuidv4 } from 'uuid'; + import { PaliInpageProviderEth } from './paliProviderEthereum'; import { shimWeb3 } from './shimWeb3'; +import { announceProvider } from './utils'; /* eslint-disable @typescript-eslint/ban-ts-comment */ // @ts-nocheck // Read files in as strings @@ -16,6 +20,12 @@ const proxiedProvider = new Proxy(ethereumProvider, { deleteProperty: () => true, }); window.ethereum = proxiedProvider; + +window.addEventListener('eip6963:requestProvider', () => { + announceProvider(proxiedProvider, uuidv4()); +}); + +announceProvider(proxiedProvider, uuidv4()); shimWeb3(proxiedProvider); export const { SUPPORTED_WALLET_METHODS } = window; diff --git a/source/scripts/ContentScript/inject/utils.ts b/source/scripts/ContentScript/inject/utils.ts index f91c7e128..4319d8fab 100644 --- a/source/scripts/ContentScript/inject/utils.ts +++ b/source/scripts/ContentScript/inject/utils.ts @@ -1,3 +1,4 @@ +import { IEIP6963ProviderInfo } from 'utils/types'; // resolve response.result or response, reject errors export const getRpcPromiseCallback = (resolve: (value?: any) => void, reject: (error?: Error) => void) => @@ -58,3 +59,18 @@ export const PALI_UTXO_METHODS = [ 'pali_isTestnet', , ]; + +export const announceProvider = (provider: any, uuid: string) => { + const providerInfo: IEIP6963ProviderInfo = { + icon: 'https://raw.githubusercontent.com/syscoin/pali-wallet/master/source/assets/icons/favicon-48.png', + name: 'Pali Wallet', + rdns: 'com.paliwallet', + uuid, + }; + + window.dispatchEvent( + new CustomEvent('eip6963:announceProvider', { + detail: Object.freeze({ info: providerInfo, provider }), + }) + ); +}; diff --git a/source/utils/types.ts b/source/utils/types.ts index 60dbfc03a..6dceb37a5 100644 --- a/source/utils/types.ts +++ b/source/utils/types.ts @@ -45,3 +45,10 @@ export interface ITransactionOptions { transaction: IEvmTransaction; wallet: IMainController; } + +export interface IEIP6963ProviderInfo { + icon: string; + name: string; + rdns: string; + uuid: string; +} diff --git a/yarn.lock b/yarn.lock index 15a67afeb..382c6630f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3253,6 +3253,11 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.1.tgz#20f18294f797f2209b5f65c8e3b5c8e8261d127c" integrity sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw== +"@types/uuid@^9.0.7": + version "9.0.7" + resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.7.tgz#b14cebc75455eeeb160d5fe23c2fcc0c64f724d8" + integrity sha512-WUtIVRUZ9i5dYXefDEAI7sh9/O7jGvHg7Df/5O/gtH3Yabe5odI3UWopVR1qbPXQtvOxWu3mM4XxlYeZtMWF4g== + "@types/w3c-web-usb@^1.0.6": version "1.0.10" resolved "https://registry.yarnpkg.com/@types/w3c-web-usb/-/w3c-web-usb-1.0.10.tgz#cf89cccd2d93b6245e784c19afe0a9f5038d4528" @@ -13429,6 +13434,11 @@ uuid@^9.0.0: resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5" integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg== +uuid@^9.0.1: + version "9.0.1" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.1.tgz#e188d4c8853cc722220392c424cd637f32293f30" + integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA== + v8-compile-cache@^2.0.3: version "2.3.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"