diff --git a/packages/extension/src/libs/recently-sent-addresses/index.ts b/packages/extension/src/libs/recently-sent-addresses/index.ts new file mode 100644 index 000000000..73f9a56ed --- /dev/null +++ b/packages/extension/src/libs/recently-sent-addresses/index.ts @@ -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, + address: string, + ): Promise { + 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 { + const key = networkName + const out: IState | undefined = await this.#storage.get(key) + if (!out) return [] + return out.addresses + } +} + +export default RecentlySentAddressesState + diff --git a/packages/extension/src/libs/recently-sent-addresses/types.ts b/packages/extension/src/libs/recently-sent-addresses/types.ts new file mode 100644 index 000000000..44976940a --- /dev/null +++ b/packages/extension/src/libs/recently-sent-addresses/types.ts @@ -0,0 +1,3 @@ +export type IState = { + addresses: string[] +} diff --git a/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue b/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue index 43b4e805a..bb8003b1c 100644 --- a/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue @@ -169,6 +169,7 @@ import { getTxInfo as getBTCTxInfo } from '@/providers/bitcoin/libs/utils'; import { NFTItem, NFTItemWithCollectionName, NFTType } from '@/types/nft'; import { trackSendEvents } from '@/libs/metrics'; import { SendEventType } from '@/libs/metrics/types'; +import RecentlySentAddressesState from '@/libs/recently-sent-addresses'; const props = defineProps({ network: { @@ -428,7 +429,14 @@ const selectNFT = (item: NFTItemWithCollectionName) => { isOpenSelectNft.value = false; }; +const recentlySentAddresses = new RecentlySentAddressesState(); + const sendAction = async () => { + await recentlySentAddresses.addRecentlySentAddress( + props.network, + addressTo.value, + ); + const keyring = new PublicKeyRing(); const fromAccountInfo = await keyring.getAccount(addressFrom.value); const currentFee = toBN( diff --git a/packages/extension/src/providers/common/ui/send-transaction/nft-select-list/components/nft-select-list-item.vue b/packages/extension/src/providers/common/ui/send-transaction/nft-select-list/components/nft-select-list-item.vue index 06e126c82..4d5f9f9d3 100644 --- a/packages/extension/src/providers/common/ui/send-transaction/nft-select-list/components/nft-select-list-item.vue +++ b/packages/extension/src/providers/common/ui/send-transaction/nft-select-list/components/nft-select-list-item.vue @@ -1,22 +1,14 @@