Skip to content

Commit

Permalink
fix: clear extension storage when disconnecting the wallet (#174)
Browse files Browse the repository at this point in the history
* Set storage values to null instead of undefined

* Fix types
  • Loading branch information
raducristianpopa committed Apr 1, 2024
1 parent 5e4b54a commit 349d6a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/background/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const defaultStorage = {
connected: false,
enabled: true,
exceptionList: {},
walletAddress: undefined,
amount: undefined,
token: undefined,
grant: undefined
walletAddress: null,
amount: null,
token: null,
grant: null,
} satisfies Omit<Storage, 'publicKey' | 'privateKey' | 'keyId'>

export class StorageService {
Expand Down
4 changes: 2 additions & 2 deletions src/popup/lib/context.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react'
import { getContextData } from '@/popup/lib/messages'
import { PopupStore } from '@/shared/types'
import { DeepNonNullable, PopupStore } from '@/shared/types'

export enum ReducerActionType {
SET_DATA = 'SET_DATA',
TOGGLE_WM = 'TOGGLE_WM'
}

export type PopupState = Required<NonNullable<PopupStore>>
export type PopupState = Required<DeepNonNullable<PopupStore>>

export interface PopupContext {
state: Required<NonNullable<PopupState>>
Expand Down
13 changes: 9 additions & 4 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export interface Storage {
/** If a wallet is connected or not */
connected: boolean
/** User wallet address information */
walletAddress?: WalletAddress | undefined
walletAddress?: WalletAddress | undefined | null
/** Overall amount */
amount?: WalletAmount | undefined
amount?: WalletAmount | undefined | null
/** Access token for quoting & outgoing payments */
token?: AccessToken | undefined
token?: AccessToken | undefined | null
/** Grant details - continue access token & uri for canceling the grant */
grant?: GrantDetails | undefined
grant?: GrantDetails | undefined | null
/** Exception list with websites and each specific amount */
exceptionList: {
[website: string]: Amount
Expand All @@ -58,3 +58,8 @@ export type PopupStore = Omit<
> & {
website: WebsiteData
}

export type DeepNonNullable<T> = {
[P in keyof T]?: NonNullable<T[P]>;
}

0 comments on commit 349d6a1

Please sign in to comment.