From 9f38e67c812d796915700c609cfb936abc41fb03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=20G=C3=A1mez=20Franco?= Date: Thu, 17 Oct 2024 15:03:39 +0200 Subject: [PATCH 1/2] Update most links to dashboard to open in quick-settings instead. --- src/components/popup/WalletHeader.tsx | 7 +++---- src/components/popup/WalletSwitcher.tsx | 16 +++++++------- src/popup.tsx | 20 ++++++++++++------ src/routes/popup/tokens.tsx | 19 +++++++++++------ src/routes/popup/transaction/[id].tsx | 28 +++++++++++++------------ 5 files changed, 54 insertions(+), 36 deletions(-) diff --git a/src/components/popup/WalletHeader.tsx b/src/components/popup/WalletHeader.tsx index db3172fd..a1a2d1c3 100644 --- a/src/components/popup/WalletHeader.tsx +++ b/src/components/popup/WalletHeader.tsx @@ -206,10 +206,9 @@ export default function WalletHeader() { { icon: , title: "setting_contacts", - route: () => - browser.tabs.create({ - url: browser.runtime.getURL("tabs/dashboard.html#/contacts") - }) + route: () => { + push("/quick-settings/contacts"); + } }, { icon: , diff --git a/src/components/popup/WalletSwitcher.tsx b/src/components/popup/WalletSwitcher.tsx index f9039b3e..e8dbca9e 100644 --- a/src/components/popup/WalletSwitcher.tsx +++ b/src/components/popup/WalletSwitcher.tsx @@ -27,6 +27,7 @@ import Arweave from "arweave"; import { svgie } from "~utils/svgies"; import { Action } from "./WalletHeader"; import copy from "copy-to-clipboard"; +import { useHistory } from "~utils/hash_router"; export default function WalletSwitcher({ open, @@ -165,6 +166,8 @@ export default function WalletSwitcher({ // toasts const { setToast } = useToasts(); + const [push] = useHistory(); + return ( {open && ( @@ -239,6 +242,7 @@ export default function WalletSwitcher({ ))} + {showOptions && ( - browser.tabs.create({ - url: browser.runtime.getURL( - `tabs/dashboard.html#/wallets/${activeAddress}` - ) - }) - } + onClick={(e) => { + e.preventDefault(); + + push(`/quick-settings/wallets/${activeAddress}`); + }} /> diff --git a/src/popup.tsx b/src/popup.tsx index f9b8c6c0..24e43030 100644 --- a/src/popup.tsx +++ b/src/popup.tsx @@ -123,16 +123,24 @@ export default function Popup() { - {(params: { id: string }) => } + {(params: { id: string }) => + params?.id === "new" ? ( + + ) : ( + + ) + } - - {(params: { address: string }) => ( - - )} + {(params: { address: string }) => + params?.address === "new" ? ( + + ) : ( + + ) + } - ( + undefined + ); // all tokens const tokens = useTokens(); // ao Tokens @@ -166,9 +168,7 @@ export default function Tokens() { onClick={() => push(`/token/${token.id}`)} onSettingsClick={(e) => { e.preventDefault(); - window.open( - `${browser.runtime.getURL("tabs/dashboard.html")}#/tokens` - ); + push(`/quick-settings/tokens/${token.id}`); }} key={i} /> @@ -192,9 +192,10 @@ export default function Tokens() { }} /> ))} + {aoSupport && hasNextPage && ( @@ -207,8 +208,14 @@ export default function Tokens() { )} )} + { + e.preventDefault(); + push("/quick-settings/tokens"); + }} > {browser.i18n.getMessage("manage_assets_button")} diff --git a/src/routes/popup/transaction/[id].tsx b/src/routes/popup/transaction/[id].tsx index 647ac69d..5af11374 100644 --- a/src/routes/popup/transaction/[id].tsx +++ b/src/routes/popup/transaction/[id].tsx @@ -151,7 +151,7 @@ export default function Transaction({ id: rawId, gw, message }: Props) { timestamp } } - } + } `, { id }, gateway @@ -381,15 +381,16 @@ export default function Transaction({ id: rawId, gw, message }: Props) { {browser.i18n.getMessage("user_not_in_contacts")}{" "} { + onClick={(e) => { + e.preventDefault(); + trackEvent(EventType.ADD_CONTACT, { fromSendFlow: true }); - browser.tabs.create({ - url: browser.runtime.getURL( - `tabs/dashboard.html#/contacts/new?address=${fromAddress}` - ) - }); + + push( + `/quick-settings/contacts/new?address=${fromAddress}` + ); }} > {browser.i18n.getMessage("create_contact")} @@ -432,15 +433,16 @@ export default function Transaction({ id: rawId, gw, message }: Props) { {browser.i18n.getMessage("user_not_in_contacts")}{" "} { + onClick={(e) => { + e.preventDefault(); + trackEvent(EventType.ADD_CONTACT, { fromSendFlow: true }); - browser.tabs.create({ - url: browser.runtime.getURL( - `tabs/dashboard.html#/contacts/new?address=${toAddress}` - ) - }); + + push( + `/quick-settings/contacts/new?address=${toAddress}` + ); }} > {browser.i18n.getMessage("create_contact")} From e29112023e9cc2a8399a7cd91b359067291e8697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=20G=C3=A1mez=20Franco?= Date: Mon, 21 Oct 2024 12:18:04 +0200 Subject: [PATCH 2/2] Add development-only snippet (commented out). --- src/injected.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/injected.ts b/src/injected.ts index 423b71e1..b4e8b0f2 100644 --- a/src/injected.ts +++ b/src/injected.ts @@ -85,6 +85,35 @@ for (const mod of modules) { // @ts-expect-error window.arweaveWallet = WalletAPI; +/* +if (process.env.NODE_ENV === "development") { + // @ts-expect-error + window.arweaveWalletDev = WalletAPI; + + console.log(`Forcing development wallet (${ WalletAPI.walletName } ${ WalletAPI.walletVersion }) to be injected...`); + + const t0 = Date.now(); + + const intervalID = setInterval(() => { + if (window.arweaveWallet && window.arweaveWallet !== WalletAPI) { + // @ts-expect-error + console.log(`Another wallet (${ window.arweaveWallet.walletName } ${ window.arweaveWallet.walletVersion }) was injected. Overriding...`); + + // @ts-expect-error + window.arweaveWallet = WalletAPI; + } + + const elapsed = Date.now() - t0; + + if (elapsed >= 30000) { + console.log(`Stopped forcing development wallet (${ WalletAPI.walletName } ${ WalletAPI.walletVersion }) to be injected.`); + + clearInterval(intervalID); + } + }, 250); +} +*/ + // at the end of the injected script, // we dispatch the wallet loaded event dispatchEvent(new CustomEvent("arweaveWalletLoaded", { detail: {} }));