From 584562d6327d32ada0e7c5f190478cf1e8d4b60d Mon Sep 17 00:00:00 2001 From: nickkelly1 Date: Thu, 2 Jan 2025 16:43:05 -0600 Subject: [PATCH] feat: recent addresses --- .../src/libs/recently-sent-addresses/index.ts | 41 ++++++++++ .../src/libs/recently-sent-addresses/types.ts | 3 + .../bitcoin/ui/send-transaction/index.vue | 12 ++- .../ui/send-transaction/send-address-item.vue | 8 +- .../send-transaction/send-contacts-list.vue | 79 +++++++++++++++++-- .../ethereum/ui/send-transaction/index.vue | 8 ++ .../kadena/ui/send-transaction/index.vue | 8 ++ .../polkadot/ui/send-transaction/index.vue | 8 ++ .../src/providers/solana/networks/solana.ts | 4 +- .../solana/ui/send-transaction/index.vue | 9 ++- packages/extension/src/types/provider.ts | 3 +- .../swap/src/providers/rango/supported.ts | 3 +- packages/swap/tests/changelly.test.ts | 4 +- 13 files changed, 170 insertions(+), 20 deletions(-) create mode 100644 packages/extension/src/libs/recently-sent-addresses/index.ts create mode 100644 packages/extension/src/libs/recently-sent-addresses/types.ts 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 66138e361..2b53e7d7c 100644 --- a/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue @@ -168,6 +168,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: { @@ -313,8 +314,8 @@ const isInputsValid = computed(() => { ) return false; - const sendAmountBigNumber = new BigNumber(sendAmount.value) - if (sendAmountBigNumber.isNaN()) return false + const sendAmountBigNumber = new BigNumber(sendAmount.value); + if (sendAmountBigNumber.isNaN()) return false; if (sendAmountBigNumber.gt(assetMaxValue.value)) return false; return true; }); @@ -427,7 +428,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/send-address-item.vue b/packages/extension/src/providers/common/ui/send-transaction/send-address-item.vue index cb940ce1e..8c845e78c 100644 --- a/packages/extension/src/providers/common/ui/send-transaction/send-address-item.vue +++ b/packages/extension/src/providers/common/ui/send-transaction/send-address-item.vue @@ -7,7 +7,7 @@
-

{{ account.name }}

+

{{ account.name }}

{{ $filters.replaceWithEllipsis( @@ -32,13 +32,17 @@ import { EnkryptAccount } from '@enkryptcom/types'; const emit = defineEmits<{ (e: 'selected:account', address: string): void; }>(); + defineProps({ network: { type: Object as PropType, default: () => ({}), }, account: { - type: Object as PropType, + type: Object as PropType<{ + name?: string; + address: string; + }>, default: () => { return {}; }, diff --git a/packages/extension/src/providers/common/ui/send-transaction/send-contacts-list.vue b/packages/extension/src/providers/common/ui/send-transaction/send-contacts-list.vue index b44d3f578..9826bf675 100644 --- a/packages/extension/src/providers/common/ui/send-transaction/send-contacts-list.vue +++ b/packages/extension/src/providers/common/ui/send-transaction/send-contacts-list.vue @@ -9,7 +9,10 @@ class="send-contacts-list__scroll-area" :settings="scrollSettings({ suppressScrollX: true })" > -

+
@@ -20,7 +23,31 @@ Paste
-

Recent

+ +

My accounts

@@ -39,7 +70,6 @@

My accounts

-
@@ -57,7 +91,7 @@