diff --git a/packages/extension/src/libs/networks-state/index.ts b/packages/extension/src/libs/networks-state/index.ts index 059540b01..37efd50f6 100644 --- a/packages/extension/src/libs/networks-state/index.ts +++ b/packages/extension/src/libs/networks-state/index.ts @@ -2,6 +2,7 @@ import BrowserStorage from "../common/browser-storage"; import { POPULAR_NAMES } from "../utils/networks"; import { InternalStorageNamespace } from "@/types/provider"; import { IState, StorageKeys, NetworkStorageElement } from "./types"; +import { newNetworks, newSwaps } from "@/providers/common/libs/new-features"; class NetworksState { private storage: BrowserStorage; @@ -14,7 +15,7 @@ class NetworksState { const networks: NetworkStorageElement[] = POPULAR_NAMES.map((name) => ({ name, })); - await this.setState({ networks }); + await this.setState({ networks, newNetworksVersion: "" }); } async setNetworkStatus( @@ -33,7 +34,7 @@ class NetworksState { } else if (!isActive) { const idxArr = state.networks.map((_, i) => i); const filteredIdx = idxArr - .filter((i) => state.networks[i].name !== targetNetwork!.name) + .filter((i) => state.networks[i].name !== targetNetwork.name) .sort((a, b) => a - b); const activeNetworks: NetworkStorageElement[] = []; filteredIdx.forEach((i) => activeNetworks.push(state.networks[i])); @@ -42,16 +43,41 @@ class NetworksState { await this.setState(state); } - async getActiveNetworkNames(): Promise { + async insertNetworksWithNewFeatures(): Promise { const state: IState | undefined = await this.getState(); - if (state && state.networks) { - const validNetworks = state.networks.filter((net) => { - if ((net as any).isActive === undefined || (net as any).isActive) { - return true; - } + if ( + state && + state.networks && + state.newNetworksVersion !== process.env.PACKAGE_VERSION + ) { + let validNetworks = state.networks; + const netsWithFeatures = [ + ...new Set([...newNetworks, ...newSwaps]), + ].sort(); + const filteredNets = netsWithFeatures.filter((n) => { + for (const vn of validNetworks) if (vn.name === n) return false; + return true; + }); + const fnetworkItem = filteredNets.map((name) => { + return { + name, + }; }); + const insertIdx = validNetworks.length > 5 ? 5 : validNetworks.length; + validNetworks = validNetworks + .slice(0, insertIdx) + .concat(fnetworkItem, validNetworks.slice(insertIdx)); state.networks = validNetworks; + state.newNetworksVersion = process.env.PACKAGE_VERSION as string; await this.setState(state); + } + } + + async getActiveNetworkNames(): Promise { + await this.insertNetworksWithNewFeatures(); + const state: IState | undefined = await this.getState(); + if (state && state.networks) { + const validNetworks = state.networks; return validNetworks.map(({ name }) => name); } else { await this.setInitialActiveNetworks(); @@ -60,10 +86,14 @@ class NetworksState { } async reorderNetwork(networkNames: string[]): Promise { + const state: IState | undefined = await this.getState(); const activeNetworks: NetworkStorageElement[] = networkNames.map( - (name) => ({ name }) + (name) => ({ name, isActive: true }) ); - await this.setState({ networks: activeNetworks }); + await this.setState({ + networks: activeNetworks, + newNetworksVersion: state.newNetworksVersion, + }); } async setState(state: IState): Promise { diff --git a/packages/extension/src/libs/networks-state/types.ts b/packages/extension/src/libs/networks-state/types.ts index db546f5b2..bd560a1f2 100644 --- a/packages/extension/src/libs/networks-state/types.ts +++ b/packages/extension/src/libs/networks-state/types.ts @@ -8,4 +8,5 @@ export interface NetworkStorageElement { export interface IState { networks: NetworkStorageElement[]; + newNetworksVersion: string; } diff --git a/packages/extension/src/providers/common/libs/new-features.ts b/packages/extension/src/providers/common/libs/new-features.ts new file mode 100644 index 000000000..d8c581533 --- /dev/null +++ b/packages/extension/src/providers/common/libs/new-features.ts @@ -0,0 +1,6 @@ +import { NetworkNames } from "@enkryptcom/types"; + +const newNetworks = [NetworkNames.Kadena, NetworkNames.Amplitude]; +const newSwaps = [NetworkNames.MaticZK, NetworkNames.Arbitrum]; + +export { newNetworks, newSwaps }; diff --git a/packages/extension/src/ui/action/components/app-menu/components/app-menu-item.vue b/packages/extension/src/ui/action/components/app-menu/components/app-menu-item.vue index 3115eed30..8d5090b87 100644 --- a/packages/extension/src/ui/action/components/app-menu/components/app-menu-item.vue +++ b/packages/extension/src/ui/action/components/app-menu/components/app-menu-item.vue @@ -3,7 +3,16 @@ {{ network.name_long }} - + New + Swap @@ -15,6 +24,7 @@ import { NodeType } from "@/types/provider"; import { PropType, ref, watch } from "vue"; import DragIcon from "@action/icons/common/drag-icon.vue"; import TestNetworkIcon from "@action/icons/common/test-network-icon.vue"; +import { newNetworks, newSwaps } from "@/providers/common/libs/new-features"; const props = defineProps({ network: { @@ -87,7 +97,42 @@ watch(