Skip to content

Commit

Permalink
feat: change query persister to chrome storage, closes #5153
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo committed Apr 5, 2024
1 parent b6864cd commit d11830c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"@stitches/react": "1.2.8",
"@storybook/addon-styling-webpack": "1.0.0",
"@styled-system/theme-get": "5.1.2",
"@tanstack/query-sync-storage-persister": "4.35.7",
"@tanstack/query-async-storage-persister": "4.35.7",
"@tanstack/react-query": "4.35.7",
"@tanstack/react-query-devtools": "4.35.7",
"@tanstack/react-query-persist-client": "4.35.7",
Expand Down
37 changes: 18 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/generate-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const manifest = {
author: 'Leather Wallet, LLC',
description:
'Leather is the only Bitcoin wallet you need to tap into the emerging Bitcoin economy.',
permissions: ['contextMenus', 'storage'],
permissions: ['contextMenus', 'storage', 'unlimitedStorage'],
commands: {
_execute_browser_action: {
suggested_key: {
Expand Down
15 changes: 12 additions & 3 deletions src/app/common/persistence.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister';
import { createAsyncStoragePersister } from '@tanstack/query-async-storage-persister';
import { QueryClient } from '@tanstack/react-query';
import { persistQueryClient } from '@tanstack/react-query-persist-client';

import { PERSISTENCE_CACHE_TIME } from '@shared/constants';
import { IS_TEST_ENV } from '@shared/environment';

const localStoragePersistor = createSyncStoragePersister({ storage: window.localStorage });
const storage = {
getItem: async (key: string) => {
const storageVal = await chrome.storage.local.get(key);
return storageVal[key];
},
setItem: (key: string, value: string) => chrome.storage.local.set({ [key]: value }),
removeItem: (key: string) => chrome.storage.local.remove([key]),
};

const chromeStorageLocalPersister = createAsyncStoragePersister({ storage });

export const queryClient = new QueryClient({
defaultOptions: {
Expand All @@ -21,7 +30,7 @@ export async function persistAndRenderApp(renderApp: () => void) {
if (!IS_TEST_ENV)
persistQueryClient({

Check warning on line 31 in src/app/common/persistence.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

An array of Promises may be unintentional. Consider handling the promises' fulfillment or rejection with Promise.all or similar, or explicitly marking the expression as ignored with the `void` operator
queryClient,
persister: localStoragePersistor,
persister: chromeStorageLocalPersister,
buster: VERSION,
});
renderApp();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useMemo } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';

import { HStack } from 'leather-styles/jsx';

import { BitcoinTx } from '@shared/models/transactions/bitcoin-transaction.model';
import { RouteUrls } from '@shared/route-urls';

Expand Down Expand Up @@ -74,10 +76,12 @@ export function BitcoinTransactionItem({ transaction }: BitcoinTransactionItemPr
isOriginator && !transaction.status.confirmed && !containsTaprootInput(transaction);

const txCaption = (
<BulletSeparator>
<Caption>{caption}</Caption>
{inscriptionData ? <Caption>{inscriptionData.mime_type}</Caption> : null}
</BulletSeparator>
<HStack gap="space.02">
<BulletSeparator>
<Caption>{caption}</Caption>
{inscriptionData ? <Caption>{inscriptionData.mime_type}</Caption> : null}
</BulletSeparator>
</HStack>
);

const title = inscriptionData ? `Ordinal inscription #${inscriptionData.number}` : 'Bitcoin';
Expand Down
2 changes: 1 addition & 1 deletion src/shared/route-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export enum RouteUrls {
ViewSecretKey = '/view-secret-key',

// nested routes must have relative paths
Activity = 'activity',
Activity = '/activity',
Receive = 'receive',
ReceiveStx = 'receive/stx',
ReceiveBtc = 'receive/btc',
Expand Down

0 comments on commit d11830c

Please sign in to comment.