Skip to content

Commit

Permalink
reduce service worker bundle size (#4260)
Browse files Browse the repository at this point in the history
  • Loading branch information
wentokay authored Jun 30, 2023
1 parent 92ef546 commit eed1348
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 41 deletions.
34 changes: 31 additions & 3 deletions packages/background/src/backend/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import {
DEFAULT_DARK_MODE,
defaultPreferences,
deserializeTransaction,
EthereumConnectionUrl,
EthereumExplorer,
getAccountRecoveryPaths,
getAddMessage,
getRecoveryPaths,
Expand Down Expand Up @@ -60,11 +58,17 @@ import {
NOTIFICATION_USER_ACCOUNT_PUBLIC_KEY_DELETED,
NOTIFICATION_USER_ACCOUNT_PUBLIC_KEYS_UPDATED,
NOTIFICATION_XNFT_PREFERENCE_UPDATED,
TAB_APPS,
TAB_BALANCES,
TAB_BALANCES_SET,
TAB_MESSAGES,
TAB_NFTS,
TAB_NOTIFICATIONS,
TAB_RECENT_ACTIVITY,
TAB_SWAP,
TAB_TOKENS,
TAB_XNFT,
} from "@coral-xyz/common";
import { makeDefaultNav } from "@coral-xyz/recoil";
import type {
BlockchainKeyring,
KeyringStore,
Expand Down Expand Up @@ -2068,6 +2072,30 @@ export class Backend {
export const SUCCESS_RESPONSE = "success";
const defaultNav = makeDefaultNav();

function makeDefaultNav() {
const defaultNav: any = {
activeTab: TAB_TOKENS,
data: {},
};
[
[TAB_BALANCES, "Balances"],
[TAB_NFTS, "Nfts"],
[TAB_SWAP, "Swap"],
[TAB_APPS, "Apps"],
[TAB_MESSAGES, "Messages"],
[TAB_RECENT_ACTIVITY, "Recent Activity"],
[TAB_NOTIFICATIONS, "Notifications"],
[TAB_TOKENS, "Tokens"],
].forEach(([tabName, tabTitle]) => {
defaultNav.data[tabName] = {
id: tabName,
urls: [makeUrl(tabName, { title: tabTitle, props: {} })],
ref: tabName === "balances" ? "tokens" : undefined,
};
});
return defaultNav;
}

function setSearchParam(url: string, key: string, value: string): string {
const [path, search] = url.split("?");
const searchParams = new URLSearchParams(search);
Expand Down
39 changes: 1 addition & 38 deletions packages/recoil/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
import {
type Blockchain,
makeUrl,
TAB_APPS,
TAB_BALANCES,
TAB_MESSAGES,
TAB_NFTS,
TAB_NOTIFICATIONS,
TAB_RECENT_ACTIVITY,
TAB_SWAP,
TAB_TOKENS,
} from "@coral-xyz/common";
import { type Blockchain } from "@coral-xyz/common";
import type { BigNumber } from "ethers";
import type { RecoilValueReadOnly } from "recoil";

Expand Down Expand Up @@ -86,32 +75,6 @@ export interface TokenMetadata {
symbol: string;
}

export const TABS = [
[TAB_BALANCES, "Balances"],
[TAB_NFTS, "Nfts"],
[TAB_SWAP, "Swap"],
[TAB_APPS, "Apps"],
[TAB_MESSAGES, "Messages"],
[TAB_RECENT_ACTIVITY, "Recent Activity"],
[TAB_NOTIFICATIONS, "Notifications"],
[TAB_TOKENS, "Tokens"],
];

export function makeDefaultNav() {
const defaultNav: any = {
activeTab: TAB_TOKENS,
data: {},
};
TABS.forEach(([tabName, tabTitle]) => {
defaultNav.data[tabName] = {
id: tabName,
urls: [makeUrl(tabName, { title: tabTitle, props: {} })],
ref: tabName === "balances" ? "tokens" : undefined,
};
});
return defaultNav;
}

export type ExtractRecoilType<P> = P extends RecoilValueReadOnly<infer T>
? T
: never;

1 comment on commit eed1348

@vercel
Copy link

@vercel vercel bot commented on eed1348 Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.