-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from enkryptcom/develop
Release 2.1.0
- Loading branch information
Showing
97 changed files
with
3,162 additions
and
626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/extension/src/libs/recently-sent-addresses/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { InternalStorageNamespace } from "@/types/provider"; | ||
import BrowserStorage from "../common/browser-storage"; | ||
import { IState, } from "./types"; | ||
import { NetworkNames } from "@enkryptcom/types"; | ||
import { BaseNetwork } from "@/types/base-network"; | ||
|
||
class RecentlySentAddressesState { | ||
#storage: BrowserStorage | ||
|
||
constructor() { | ||
this.#storage = new BrowserStorage( | ||
InternalStorageNamespace.recentlySentAddresses, | ||
); | ||
} | ||
|
||
async addRecentlySentAddress( | ||
network: Pick<BaseNetwork, 'name' | 'displayAddress'>, | ||
address: string, | ||
): Promise<void> { | ||
const key = network.name | ||
const state: IState | undefined = await this.#storage.get(key) | ||
const newState: IState = { | ||
...state, | ||
addresses: Array.from(new Set([ | ||
network.displayAddress(address), | ||
...(state?.addresses ?? []), | ||
])).slice(0, 5), | ||
} | ||
await this.#storage.set(key, newState) | ||
} | ||
|
||
async getRecentlySentAddresses(networkName: NetworkNames): Promise<string[]> { | ||
const key = networkName | ||
const out: IState | undefined = await this.#storage.get(key) | ||
if (!out) return [] | ||
return out.addresses | ||
} | ||
} | ||
|
||
export default RecentlySentAddressesState | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type IState = { | ||
addresses: string[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import BrowserStorage from '../common/browser-storage'; | ||
import { InternalStorageNamespace } from '@/types/provider'; | ||
import { IState, StorageKeys } from './types'; | ||
|
||
class UpdatesState { | ||
private storage: BrowserStorage; | ||
|
||
constructor() { | ||
this.storage = new BrowserStorage(InternalStorageNamespace.updatesState); | ||
} | ||
|
||
async setState(state: IState): Promise<void> { | ||
return this.storage.set(StorageKeys.updatesInfo, state); | ||
} | ||
|
||
async getState(): Promise<IState> { | ||
const state = this.storage.get(StorageKeys.updatesInfo); | ||
if (!state) { | ||
const newState: IState = { | ||
lastVersionViewed: '', | ||
currentRelease: '', | ||
currentReleaseTimestamp: 0, | ||
} | ||
return newState | ||
} | ||
return state; | ||
} | ||
|
||
async getLastVersionViewed(): Promise<IState['lastVersionViewed']> { | ||
const state: IState = await this.getState(); | ||
return state?.lastVersionViewed ?? ''; | ||
} | ||
async setLastVersionViewed(lastVersionViewed: string): Promise<void> { | ||
const state: IState = await this.getState(); | ||
const newState: IState = { ...state, lastVersionViewed } | ||
await this.setState(newState); | ||
} | ||
|
||
async getCurrentRelease(): Promise<IState['currentRelease']> { | ||
const state: IState = await this.getState(); | ||
return state?.currentRelease ?? ''; | ||
} | ||
|
||
async setCurrentRelease(currentRelease: string): Promise<void> { | ||
const state: IState = await this.getState(); | ||
const newState: IState = { ...state, currentRelease } | ||
await this.setState(newState); | ||
} | ||
|
||
async getCurrentReleaseTimestamp(): Promise<IState['currentReleaseTimestamp']> { | ||
const state: IState = await this.getState(); | ||
return state?.currentReleaseTimestamp ?? 0; | ||
} | ||
|
||
async setCurrentReleaseTimestamp(currentReleaseTimestamp: number): Promise<void> { | ||
const state: IState = await this.getState(); | ||
const newState: IState = { ...state, currentReleaseTimestamp } | ||
await this.setState(newState); | ||
} | ||
} | ||
|
||
export default UpdatesState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export enum StorageKeys { | ||
updatesInfo = 'updates-info', | ||
} | ||
|
||
export interface IState { | ||
lastVersionViewed: string; | ||
currentRelease: string; | ||
currentReleaseTimestamp: number; | ||
} |
Oops, something went wrong.