Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement EIP-6963 #541

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions source/scripts/ContentScript/inject/inpage.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
16 changes: 16 additions & 0 deletions source/scripts/ContentScript/inject/utils.ts
Original file line number Diff line number Diff line change
@@ -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) =>
Expand Down Expand Up @@ -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 }),
})
);
};
7 changes: 7 additions & 0 deletions source/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ export interface ITransactionOptions {
transaction: IEvmTransaction;
wallet: IMainController;
}

export interface IEIP6963ProviderInfo {
icon: string;
name: string;
rdns: string;
uuid: string;
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading