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

Config-based routing, wouter v3, custom useLocation() / navigate() #556

Merged
merged 54 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
cbd7574
Vite build setup for the embedded wallet iframe (re)using ArConnect.
Danziger Oct 15, 2024
6150087
Mock enough stuff for the app to build and kind of run with Vite.
Danziger Oct 16, 2024
5beaf0c
Implement route guard logic wihout using a regular Route.
Danziger Oct 16, 2024
60377a8
Merge development and resolve conflicts.
Danziger Oct 22, 2024
7171c38
Minor changes in the mocked create tab functionality.
Danziger Oct 22, 2024
ffd83b9
Merge feature/reorganize-wallet-installation-n-setup and resolve conf…
Danziger Nov 25, 2024
bd94717
Add some more scaffolding for the embedded wallet SDK.
Danziger Nov 25, 2024
76bc10c
Partial restructuring of browser extension & embedded wallets setup h…
Danziger Nov 25, 2024
0b78ab6
Move routes to a config file (WIP).
Danziger Nov 26, 2024
48d7a70
Finish router refactoring to make it config-driven.
Danziger Nov 27, 2024
f819c4b
Memoize Routes, extract route paths to constant and add authID to Aut…
Danziger Nov 27, 2024
26ef8d4
Fix broken import.
Danziger Nov 27, 2024
8e07997
Add mock for the Alarms API.
Danziger Nov 27, 2024
2ae4dd9
Add storage mock.
Danziger Nov 28, 2024
c7c7964
Re-strucute browser mocks.
Danziger Nov 28, 2024
8ddbc94
Remove tabs.create() mocks to open Welcome or Dashboard pages.
Danziger Nov 28, 2024
3b9a7dc
Replace window.top.close() in AuthRequestsProvider.
Danziger Nov 28, 2024
06fb97c
Remove embedded wallet / iframe files from this branch.
Danziger Nov 29, 2024
35ab26a
Update yarn.lock.
Danziger Nov 29, 2024
6a94bfe
Update yarn.lock.
Danziger Nov 29, 2024
46ea22b
Remove debugging code.
Danziger Nov 29, 2024
1300615
Remove code that doesn't belong in this PR.
Danziger Nov 29, 2024
2e3c95b
Remove code that doesn't belong in this PR.
Danziger Nov 29, 2024
0c925ba
Remove vite.config.js
Danziger Nov 29, 2024
0ec54a3
Remove HistoryProvider and use a custom useLocation hook everywhere.
Danziger Nov 29, 2024
b0993ef
Update Welcome pages to get params from props (WIP).
Danziger Dec 2, 2024
fd9dd95
Add types for routes.
Danziger Dec 3, 2024
79d0343
Remove unused imports.
Danziger Dec 3, 2024
4c3b8d8
Refactor (rename) Dashboard views and some rounting checks.
Danziger Dec 3, 2024
4ef2f12
Extract SubscriptionListItem and TokenListItem.
Danziger Dec 4, 2024
516cd80
Clean up TODO comments, unused imports and minor TS issues.
Danziger Dec 4, 2024
c87eabf
Undo pre-commit hook change.
Danziger Dec 4, 2024
b26ef26
Remove/replace some imports from wouter.
Danziger Dec 4, 2024
695c34f
Fix incorrect redirect.
Danziger Dec 4, 2024
3d113d2
Get quickSettingsMenuItems from basicSettings.
Danziger Dec 4, 2024
42742ac
Refactor all Dashboard subsetting views to use Routes and params.
Danziger Dec 4, 2024
2ee1591
Update useLocations's navigate function to accept a search param.
Danziger Dec 4, 2024
3131d5a
Add a useSearchParams() hook.
Danziger Dec 4, 2024
fe37222
Add missing params property.
Danziger Dec 4, 2024
8d8488a
Fix Dashboard panels layout.
Danziger Dec 4, 2024
c3a0268
Add special prev/next/up values to navigate().
Danziger Dec 4, 2024
c61f654
Add special prev/next/up values to navigate().
Danziger Dec 4, 2024
42dfd93
Merge development and resolve conflicts.
Danziger Dec 4, 2024
fccb2f7
Remove value from binary props (isQuickSetting).
Danziger Dec 4, 2024
bd08652
Update useLocation() / navigate() to accept number paths.
Danziger Dec 4, 2024
2c67339
Remove console.log()s.
Danziger Dec 4, 2024
3b225de
- Fix casing issue in subscriptionDetails.tsx SVG.
Danziger Dec 6, 2024
f7bfaee
Merge branch 'development' into feature/config-based-router
Danziger Dec 9, 2024
70f1042
Fix infinite re-render caused by useGateway params.
Danziger Dec 10, 2024
2f2a5d9
Fix Setting instances not rendering in the Dashboard.
Danziger Dec 10, 2024
248d3d4
Fix route params used in ConfirmView and RecipientView.
Danziger Dec 10, 2024
630a7a6
Remove unused RecipientView and fix back functionality.
Danziger Dec 10, 2024
f6ef12f
Fix back functionality and add clarification comments about certain m…
Danziger Dec 10, 2024
379ab20
Merge development and resolve conflicts.
Danziger Dec 10, 2024
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: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname -- "$0")/_/husky.sh"

yarn fmt
git add -A
git add -A
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>ArConnect Embedded Wallet</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="/assets/popup.css" />
</head>
<body>
<div id="cover"></div>
<div id="root"></div>
<!-- <script type="text/javascript" src="/assets/popup.js"></script> -->
<script type="module" src="/src/iframe/main.tsx"></script>
</body>
</html>
24 changes: 16 additions & 8 deletions src/api/background/background-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ import {
handleTabClosed,
handleTabUpdate
} from "~api/background/handlers/browser/tabs/tabs.handler";
import { log, LOG_GROUP } from "~utils/log/log.utils";

export function setupBackgroundService() {
log(
LOG_GROUP.SETUP,
`background-setup.ts > setupBackgroundService(PLASMO_PUBLIC_APP_TYPE = "${process.env.PLASMO_PUBLIC_APP_TYPE}")`
);

// MESSAGES:
// Watch for API call and chunk messages:
onMessage("api_call", handleApiCallMessage);
Expand All @@ -36,12 +42,9 @@ export function setupBackgroundService() {
// LIFECYCLE:

// Open welcome page on extension install.
// TODO: This needs to be adapted to work with the embedded wallet (it cannot just be removed / skipped):
browser.runtime.onInstalled.addListener(handleInstall);

// ALARMS:
// TODO: Mock/polyfill alarms to work with setTimeout/clearTimeout and also a lazy version that just checks the last update time on start.

browser.alarms.onAlarm.addListener(handleNotificationsAlarm);
browser.alarms.onAlarm.addListener(handleSubscriptionsAlarm);
browser.alarms.onAlarm.addListener(handleTrackBalanceAlarm);
Expand Down Expand Up @@ -74,19 +77,24 @@ export function setupBackgroundService() {
});

// listen for app config updates
// `ExtensionStorage.watch` requires a callbackMap param, so this cannot be done using `ExtensionStorage` directly.
browser.storage.onChanged.addListener(handleAppConfigChange);

// ONLY EXTENSION:
if (process.env.PLASMO_PUBLIC_APP_TYPE !== "extension") return;

// ONLY BROWSER EXTENSION BELOW THIS LINE:

// When the last window connected to the extension is closed, the decryption key will be removed from memory. This is no needed in the embedded wallet because
// each wallet instance will be removed automatically when its tab/window is closed.
browser.windows.onRemoved.addListener(handleWindowClose);

// handle tab change (icon, context menus)
browser.tabs.onUpdated.addListener((tabId, changeInfo) =>
handleTabUpdate(tabId, changeInfo)
);
browser.tabs.onActivated.addListener(({ tabId }) => handleTabUpdate(tabId));
browser.tabs.onUpdated.addListener((tabId, changeInfo) => {
handleTabUpdate(tabId, changeInfo);
});
browser.tabs.onActivated.addListener(({ tabId }) => {
handleTabUpdate(tabId);
});
browser.tabs.onRemoved.addListener(handleTabClosed);

// handle ar:// protocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function handleAppConfigChange(
storedNewValue as unknown as string
) as InitAppParams;

// check if permission event emiting is needed
// check if permission event emitting is needed
// get missing permissions
const missingPermissions = getMissingPermissions(
oldValue?.permissions || [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Loading } from "@arconnect/components";
import styled from "styled-components";
import { Page } from "~components/popup/Route";
import { withPage } from "~components/page/page.utils";

export interface LoadingPageProps {
export interface LoadingViewProps {
label?: string;
}

export const LoadingPage = ({ label }: LoadingPageProps) => {
export const LoadingView = ({ label }: LoadingViewProps) => {
return (
<Page>
<DivWrapper>
<Loading style={{ width: "32px", height: "32px" }} />
<PLabel>{label || "Loading..."}</PLabel>
</DivWrapper>
</Page>
<DivWrapper>
<Loading style={{ width: "32px", height: "32px" }} />
<PLabel>{label || "Loading..."}</PLabel>
</DivWrapper>
);
};

export const LoadingPage = withPage(LoadingView);

const DivWrapper = styled.div`
display: flex;
flex-direction: column;
Expand Down
33 changes: 33 additions & 0 deletions src/components/page/page.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { type Variants, motion } from "framer-motion";
import type { PropsWithChildren } from "react";
import styled from "styled-components";

export interface PageProps extends PropsWithChildren {}

export function Page({ children }: PageProps) {
const opacityAnimation: Variants = {
initial: { opacity: 0 },
enter: { opacity: 1 },
exit: { opacity: 0, y: 0, transition: { duration: 0.2 } }
};

return (
<Main
initial="initial"
animate="enter"
exit="exit"
variants={opacityAnimation}
data-test-id="Page"
>
{children}
</Main>
);
}

const Main = styled(motion.main)`
position: relative;
top: 0;
width: 100%;
min-height: 100vh;
max-height: max-content;
`;
15 changes: 15 additions & 0 deletions src/components/page/page.utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Page } from "~components/page/page.component";

export function withPage<P>(Component: React.ComponentType<P>) {
const PageComponent = (props: P) => {
return (
<Page>
<Component {...props} />
</Page>
);
};

PageComponent.displayName = `${Component.displayName || "Anonymous"}Page`;

return PageComponent;
}
2 changes: 1 addition & 1 deletion src/components/popup/Head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import HardwareWalletIcon, {
hwIconAnimateProps
} from "~components/hardware/HardwareWalletIcon";
import { useHardwareApi } from "~wallets/hooks";
import { useHistory } from "~utils/hash_router";
import { useHistory } from "~wallets/router/hash/hash-router.hook";
import { useEffect, useMemo, useState } from "react";
import keystoneLogo from "url:/assets/hardware/keystone.png";
import WalletSwitcher from "./WalletSwitcher";
Expand Down
2 changes: 1 addition & 1 deletion src/components/popup/HeadV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import HardwareWalletIcon, {
hwIconAnimateProps
} from "~components/hardware/HardwareWalletIcon";
import { useHardwareApi } from "~wallets/hooks";
import { useHistory } from "~utils/hash_router";
import { useHistory } from "~wallets/router/hash/hash-router.hook";
import React, { useEffect, useMemo, useState } from "react";
import keystoneLogo from "url:/assets/hardware/keystone.png";
import WalletSwitcher from "./WalletSwitcher";
Expand Down
4 changes: 3 additions & 1 deletion src/components/popup/HistoryProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
type HistoryAction,
HistoryContext,
type PushAction
} from "~utils/hash_router";
} from "~wallets/router/hash/hash-router.hook";

// TODO: Do we really need this instead of simply calling history.back()?

export default function HistoryProvider({ children }: PropsWithChildren<{}>) {
// current history action
Expand Down
8 changes: 6 additions & 2 deletions src/components/popup/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,34 @@ import {
import browser from "webextension-polyfill";
import styled from "styled-components";
import { useLocation } from "wouter";
import { useHistory } from "~utils/hash_router";
import { useHistory } from "~wallets/router/hash/hash-router.hook";
import { useTheme } from "~utils/theme";

const buttons = [
{
title: "Home",
dictionaryKey: "home",
icon: <Home02 />,
size: "24px",
route: "/"
},
{
title: "Send",
dictionaryKey: "send",
icon: <ArrowUpRight />,
size: "24px",
route: "/send/transfer"
},
{
title: "Receive",
dictionaryKey: "receive",
icon: <ArrowDownLeft />,
size: "24px",
route: "/receive"
},
{
title: "Explore",
dictionaryKey: "explore",
icon: <Compass03 />,
size: "24px",

Expand Down Expand Up @@ -71,7 +75,7 @@ export const NavigationBar = () => {
<IconWrapper displayTheme={theme} size={button.size}>
{button.icon}
</IconWrapper>
<div>{browser.i18n.getMessage(button.title)}</div>
<div>{browser.i18n.getMessage(button.dictionaryKey)}</div>
</NavigationButton>
);
})}
Expand Down
51 changes: 0 additions & 51 deletions src/components/popup/Route.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/popup/WalletHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
Users01
} from "@untitled-ui/icons-react";
import { svgie } from "~utils/svgies";
import { useHistory } from "~utils/hash_router";
import { useHistory } from "~wallets/router/hash/hash-router.hook";
import WalletMenu from "./WalletMenu";

export default function WalletHeader() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/popup/WalletSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +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";
import { useHistory } from "~wallets/router/hash/hash-router.hook";

export default function WalletSwitcher({
open,
Expand Down Expand Up @@ -58,7 +58,7 @@ export default function WalletSwitcher({
useEffect(
() =>
setWallets(
storedWallets.map((wallet) => ({
(storedWallets || []).map((wallet) => ({
name: wallet.nickname,
address: wallet.address,
balance: "0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/popup/home/BuyButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useHistory } from "~utils/hash_router";
import { useHistory } from "~wallets/router/hash/hash-router.hook";
import { Button, ButtonV2 } from "@arconnect/components";
import browser from "webextension-polyfill";
import styled from "styled-components";
Expand Down
2 changes: 1 addition & 1 deletion src/components/popup/home/Collectibles.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Heading, TokenCount, ViewAll } from "../Title";
import { Spacer, Text } from "@arconnect/components";
import { useHistory } from "~utils/hash_router";
import { useHistory } from "~wallets/router/hash/hash-router.hook";
import { useTokens } from "~tokens";
import { useMemo } from "react";
import browser from "webextension-polyfill";
Expand Down
2 changes: 1 addition & 1 deletion src/components/popup/home/NoBalance.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ButtonV2, Section, Text } from "@arconnect/components";
import { ArrowRightIcon } from "@iconicicons/react";
import { useHistory } from "~utils/hash_router";
import { useHistory } from "~wallets/router/hash/hash-router.hook";
import noBalanceArt from "url:/assets/ar/no_funds.png";
import browser from "webextension-polyfill";
import styled from "styled-components";
Expand Down
2 changes: 1 addition & 1 deletion src/components/popup/home/Tokens.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Heading, TokenCount, ViewAll } from "../Title";
import { Spacer, Text } from "@arconnect/components";
import { useHistory } from "~utils/hash_router";
import { useHistory } from "~wallets/router/hash/hash-router.hook";
import { useTokens } from "~tokens";
import { useMemo } from "react";
import browser from "webextension-polyfill";
Expand Down
2 changes: 1 addition & 1 deletion src/components/popup/home/Transactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
AR_SENT_QUERY,
PRINT_ARWEAVE_QUERY
} from "~notifications/utils";
import { useHistory } from "~utils/hash_router";
import { useHistory } from "~wallets/router/hash/hash-router.hook";
import { getArPrice } from "~lib/coingecko";
import useSetting from "~settings/hook";
import { printTxWorkingGateways, txHistoryGateways } from "~gateways/gateway";
Expand Down
33 changes: 0 additions & 33 deletions src/iframe-placeholder.ts

This file was deleted.

Loading