From 5b3cc7b06e0ea41a17ead192f161d7d1bd7f28d2 Mon Sep 17 00:00:00 2001 From: Ben Booth Date: Fri, 2 Sep 2022 12:13:16 +1000 Subject: [PATCH 1/2] Fix select network and add token requests If ethereum provider is a class, spreading it onto a new object won't copy methods to the new object --- src/config/tools/methods.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/config/tools/methods.ts b/src/config/tools/methods.ts index 2eef27a0..3cce26ea 100644 --- a/src/config/tools/methods.ts +++ b/src/config/tools/methods.ts @@ -6,10 +6,8 @@ import { export function selectNetwork (chainID:any, type?: any) { return new Promise(resolve => { const { ethereum } = window - const ethereumFN:any = { - request: '', - ...ethereum - } + const ethereumFN: any = ethereum; + ethereumFN.request = (ethereum as any).request ?? ''; localStorage.setItem(ENV_NODE_CONFIG, chainInfo[chainID].label) if (ethereumFN && ethereumFN.request) { // console.log(ethereumFN) @@ -59,10 +57,8 @@ export function selectNetwork (chainID:any, type?: any) { export function addToken (address:string, symbol: string, decimals: number, logoUrl?:string) { return new Promise(resolve => { const { ethereum } = window - const ethereumFN:any = { - request: '', - ...ethereum - } + const ethereumFN: any = ethereum; + ethereumFN.request = (ethereum as any).request ?? ''; if (ethereumFN && ethereumFN.request) { const params = { method: 'wallet_watchAsset', From 34578014c548418c8a4cc163193e807d39eb359e Mon Sep 17 00:00:00 2001 From: Ben Booth Date: Wed, 21 Sep 2022 10:25:41 +1000 Subject: [PATCH 2/2] Prevent errors if window.ethereum is undefined --- src/config/tools/methods.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/config/tools/methods.ts b/src/config/tools/methods.ts index 019dffd0..04a935b1 100644 --- a/src/config/tools/methods.ts +++ b/src/config/tools/methods.ts @@ -6,10 +6,9 @@ import { export function selectNetwork (chainID:any, type?: any) { return new Promise(resolve => { const { ethereum } = window - const ethereumFN: any = ethereum; - ethereumFN.request = (ethereum as any).request ?? ''; + const ethereumFN: any = ethereum ?? {}; window.localStorage.setItem(ENV_NODE_CONFIG, chainInfo[chainID].label) - if (ethereumFN && ethereumFN.request) { + if (ethereumFN.request) { // console.log(ethereumFN) // console.log(ethereumFN.chainId) const data = { @@ -56,9 +55,8 @@ export function selectNetwork (chainID:any, type?: any) { export function addToken (address:string, symbol: string, decimals: number, logoUrl?:string) { return new Promise(resolve => { const { ethereum } = window - const ethereumFN: any = ethereum; - ethereumFN.request = (ethereum as any).request ?? ''; - if (ethereumFN && ethereumFN.request) { + const ethereumFN: any = ethereum ?? {}; + if (ethereumFN.request) { const params = { method: 'wallet_watchAsset', params: {