Skip to content

Commit

Permalink
fix: conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
gamalielhere committed Jan 9, 2025
2 parents 839f0e4 + 5deedd9 commit ab6e97b
Show file tree
Hide file tree
Showing 31 changed files with 290 additions and 58 deletions.
41 changes: 41 additions & 0 deletions packages/extension/src/libs/recently-sent-addresses/index.ts
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

3 changes: 3 additions & 0 deletions packages/extension/src/libs/recently-sent-addresses/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type IState = {
addresses: string[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
<template>
<a class="nft-select-list__token" @click="$emit('selectNft', item)">
<div class="nft-select-list__token-info">
<img :src="item.image" />
<img :src="item.image" @error="imageLoadError" />

<div class="nft-select-list__token-info-name">
<h4>
{{
item.name.length > 40
? item.name.substring(0, 40) + '...'
: item.name
}}
{{ $filters.truncate(item.name, 25) }}
</h4>
<p>
{{
item.collectionName.length > 50
? item.collectionName.substring(0, 50) + '...'
: item.collectionName
}}
{{ $filters.truncate(item.collectionName, 50) }}
</p>
</div>
</div>
Expand All @@ -26,6 +18,7 @@
<script setup lang="ts">
import { PropType } from 'vue';
import { NFTItemWithCollectionName } from '@/types/nft';
import { imageLoadError } from '@/ui/action/utils/misc';
defineEmits<{
(e: 'selectNft', data: NFTItemWithCollectionName): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<img :src="network.identicon(network.displayAddress(account.address))" />

<div class="send-address-item__name">
<h4>{{ account.name }}</h4>
<h4 v-if="account.name != null">{{ account.name }}</h4>
<p>
{{
$filters.replaceWithEllipsis(
Expand All @@ -32,13 +32,17 @@ import { EnkryptAccount } from '@enkryptcom/types';
const emit = defineEmits<{
(e: 'selected:account', address: string): void;
}>();
defineProps({
network: {
type: Object as PropType<BaseNetwork>,
default: () => ({}),
},
account: {
type: Object as PropType<EnkryptAccount>,
type: Object as PropType<{
name?: string;
address: string;
}>,
default: () => {
return {};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
class="send-contacts-list__scroll-area"
:settings="scrollSettings({ suppressScrollX: true })"
>
<div v-if="!isMyAddress" class="send-contacts-list__block">
<div
v-if="recentlySentAddresses && !isMyAddress"
class="send-contacts-list__block"
>
<div class="send-contacts-list__buttons">
<base-button title="Send to my address" :click="sendToMyAddress" />

Expand All @@ -20,15 +23,43 @@
<paste-icon /> Paste
</a>
</div>
<h3>Recent</h3>
<template v-if="recentlySentAddresses.length">
<h3>Recent</h3>
<div class="send-contacts-list__list">
<send-address-item
v-for="(recentAddress, index) in recentlySentAddresses"
:key="index"
:account="{
address: recentAddress,
name: accountInfo.activeAccounts.find(
account =>
network.displayAddress(account.address) ===
network.displayAddress(recentAddress),
)?.name,
}"
:network="network"
v-bind="$attrs"
:is-checked="
!!address &&
network.displayAddress(address) ===
network.displayAddress(recentAddress)
"
/>
</div>
</template>
<h3>My accounts</h3>
<div class="send-contacts-list__list">
<send-address-item
v-for="(account, index) in accountInfo.activeAccounts"
:key="index"
:account="account"
:network="network"
v-bind="$attrs"
:is-checked="address == account.address"
:is-checked="
!!address &&
network.displayAddress(address) ===
network.displayAddress(account.address)
"
/>
</div>
</div>
Expand All @@ -39,15 +70,18 @@
</a>
<h4>My accounts</h4>
</div>

<div class="send-contacts-list__list">
<send-address-item
v-for="(account, index) in accountInfo.activeAccounts"
:key="index"
:account="account"
:network="network"
v-bind="$attrs"
:is-checked="address == account.address"
:is-checked="
!!address &&
network.displayAddress(address) ===
network.displayAddress(account.address)
"
/>
</div>
</div>
Expand All @@ -57,7 +91,7 @@
</template>

<script setup lang="ts">
import { PropType, ref } from 'vue';
import { onMounted, PropType, ref } from 'vue';
import SendAddressItem from './send-address-item.vue';
import CustomScrollbar from '@action/components/custom-scrollbar/index.vue';
import BaseButton from '@action/components/base-button/index.vue';
Expand All @@ -66,6 +100,7 @@ import scrollSettings from '@/libs/utils/scroll-settings';
import { BaseNetwork } from '@/types/base-network';
import PasteIcon from '@action/icons/actions/paste.vue';
import ArrowBack from '@action/icons/common/arrow-back.vue';
import RecentlySentAddressesState from '@/libs/recently-sent-addresses';
const emit = defineEmits<{
(e: 'update:pasteFromClipboard'): void;
Expand All @@ -74,7 +109,7 @@ const emit = defineEmits<{
const isMyAddress = ref(false);
defineProps({
const props = defineProps({
showAccounts: Boolean,
accountInfo: {
type: Object as PropType<AccountsHeaderData>,
Expand All @@ -90,6 +125,36 @@ defineProps({
},
});
const recentlySentAddressesState = new RecentlySentAddressesState();
const recentlySentAddresses = ref<null | string[]>(null);
onMounted(async function () {
let timedOut = false;
const timeout = setTimeout(function () {
console.error('Timed out getting recently sent addresses');
recentlySentAddresses.value = [];
timedOut = true;
}, 500);
try {
const addresses = await recentlySentAddressesState.getRecentlySentAddresses(
props.network.name,
);
if (!timedOut) {
recentlySentAddresses.value = Array.from(
new Set(
addresses.map(address => props.network.displayAddress(address)),
),
);
}
} catch (err) {
console.error('Error getting recently sent addresses', err);
recentlySentAddresses.value = [];
} finally {
clearTimeout(timeout);
}
});
const close = () => {
emit('close', false);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@
<div class="send-nft-select__wrap">
<a class="send-nft-select" @click="$emit('toggleSelect', item.id !== '')">
<div class="send-nft-select__image">
<img v-if="item.image !== ''" :src="item.image" alt="" />
<img :src="item.image" alt="" @error="imageLoadError" />
</div>
<div class="send-nft-select__info">
<h5>
{{
item.name.length > 25
? item.name.substring(0, 25) + '...'
: item.name
}}
{{ $filters.truncate(item.name, 25) }}
</h5>
<p>
{{
item.collectionName.length > 50
? item.collectionName.substring(0, 50) + '...'
: item.collectionName
}}
{{ $filters.truncate(item.collectionName, 50) }}
</p>
</div>

Expand All @@ -43,6 +35,7 @@
import { PropType } from 'vue';
import SwitchArrow from '@action/icons/header/switch_arrow.vue';
import { NFTItemWithCollectionName } from '@/types/nft';
import { imageLoadError } from '@/ui/action/utils/misc';
defineEmits<{
(e: 'toggleSelect', val: boolean): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CoingeckoPlatform, NetworkNames } from '@enkryptcom/types';
import { EvmNetwork, EvmNetworkOptions } from '../types/evm-network';
import assetsInfoHandler from '@/providers/ethereum/libs/assets-handlers/assetinfo-mew';
import shNFTHandler from '@/libs/nft-handlers/simplehash';
import wrapActivityHandler from '@/libs/activity-state/wrap-activity-handler';

const arbNovaOptions: EvmNetworkOptions = {
name: NetworkNames.ArbitrumNova,
Expand All @@ -20,7 +21,7 @@ const arbNovaOptions: EvmNetworkOptions = {
coingeckoPlatform: CoingeckoPlatform.ArbitrumNova,
assetsInfoHandler,
NFTHandler: shNFTHandler,
activityHandler: () => Promise.resolve([]),
activityHandler: wrapActivityHandler(() => Promise.resolve([])),
};

const arb = new EvmNetwork(arbNovaOptions);
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/providers/ethereum/networks/bsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const bscOptions: EvmNetworkOptions = {
basePath: "m/44'/714'",
NFTHandler: shNFTHandler,
assetsInfoHandler,
activityHandler: wrapActivityHandler(EtherscanActivity),
activityHandler: wrapActivityHandler(() => Promise.resolve([])),
};

const bsc = new EvmNetwork(bscOptions);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import icon from './icons/eth.svg';
import { NetworkNames } from '@enkryptcom/types';
import { EvmNetwork, EvmNetworkOptions } from '../types/evm-network';
import wrapActivityHandler from '@/libs/activity-state/wrap-activity-handler';

const holeskyOptions: EvmNetworkOptions = {
name: NetworkNames.Holesky,
Expand All @@ -14,7 +15,7 @@ const holeskyOptions: EvmNetworkOptions = {
currencyNameLong: 'Holesky',
node: 'wss://nodes.mewapi.io/ws/holesky',
icon,
activityHandler: () => Promise.resolve([]),
activityHandler: wrapActivityHandler(() => Promise.resolve([])),
};

const holesky = new EvmNetwork(holeskyOptions);
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/providers/ethereum/networks/op-bnb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CoingeckoPlatform, NetworkNames } from '@enkryptcom/types';
import { EvmNetwork, EvmNetworkOptions } from '../types/evm-network';
import assetsInfoHandler from '@/providers/ethereum/libs/assets-handlers/assetinfo-mew';
import shNFTHandler from '@/libs/nft-handlers/simplehash';
import wrapActivityHandler from '@/libs/activity-state/wrap-activity-handler';

const opBnbOptions: EvmNetworkOptions = {
name: NetworkNames.OpBNB,
Expand All @@ -20,7 +21,7 @@ const opBnbOptions: EvmNetworkOptions = {
coingeckoPlatform: CoingeckoPlatform.OpBNB,
assetsInfoHandler,
NFTHandler: shNFTHandler,
activityHandler: () => Promise.resolve([]),
activityHandler: wrapActivityHandler(() => Promise.resolve([])),
};

const op = new EvmNetwork(opBnbOptions);
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/providers/ethereum/networks/palm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import icon from './icons/palm.svg';
import { NetworkNames } from '@enkryptcom/types';
import { EvmNetwork, EvmNetworkOptions } from '../types/evm-network';
import shNFTHandler from '@/libs/nft-handlers/simplehash';
import wrapActivityHandler from '@/libs/activity-state/wrap-activity-handler';

// Palm network has an API but it seems broken (DNS won't resolve)
// @see https://palm.chainlens.com/api/swagger-ui/index.html
Expand All @@ -20,7 +21,7 @@ const palmNetworkOptions: EvmNetworkOptions = {
icon,
coingeckoID: 'palm-ai',
NFTHandler: shNFTHandler,
activityHandler: () => Promise.resolve([]),
activityHandler: wrapActivityHandler(() => Promise.resolve([])),
};

const palmNetwork = new EvmNetwork(palmNetworkOptions);
Expand Down
Loading

0 comments on commit ab6e97b

Please sign in to comment.