From 55f352e4736062447234de180798078123ecaa67 Mon Sep 17 00:00:00 2001 From: Luka Jeran Date: Fri, 5 Jul 2024 22:22:53 +0200 Subject: [PATCH] Differentiate first AddToMetaMask success and repeated clicks --- src/AddToMetaMask.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/AddToMetaMask.tsx b/src/AddToMetaMask.tsx index e143b6e5ef..8e5cfd9b34 100644 --- a/src/AddToMetaMask.tsx +++ b/src/AddToMetaMask.tsx @@ -18,6 +18,7 @@ const AddToMetaMask = (props: { if (!window.ethereum?.request) { return alert('Have you installed MetaMask yet? If not, please do so.\n\nComputer: Once it is installed, you will be able to add the ParaTime to your MetaMask.\n\nPhone: Open the website through your MetaMask Browser to add the ParaTime.') } + const startTime = Date.now() window.ethereum.request({ method: 'wallet_addEthereumChain', params: [ @@ -34,7 +35,9 @@ const AddToMetaMask = (props: { }, ], }).then(response => { - if (response === null) alert('Added') + // XXX: A workaround to figure out if the RPC already exists. + const isAutomatedResponse = Date.now() - startTime < 100 + if (response === null && isAutomatedResponse) alert(`The ${props.name} RPC already added.`) }) }} >