-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eec3ed6
commit 584562d
Showing
13 changed files
with
170 additions
and
20 deletions.
There are no files selected for viewing
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
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
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