Skip to content

Commit

Permalink
Merge branch 'feat/new-net-tags' into devop/release-1-40
Browse files Browse the repository at this point in the history
  • Loading branch information
kvhnuke committed May 8, 2024
2 parents 4815b4d + b1b536e commit 0676512
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 369 deletions.
50 changes: 40 additions & 10 deletions packages/extension/src/libs/networks-state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -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]));
Expand All @@ -42,16 +43,41 @@ class NetworksState {
await this.setState(state);
}

async getActiveNetworkNames(): Promise<string[]> {
async insertNetworksWithNewFeatures(): Promise<void> {
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<string[]> {
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();
Expand All @@ -60,10 +86,14 @@ class NetworksState {
}

async reorderNetwork(networkNames: string[]): Promise<void> {
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<void> {
Expand Down
1 change: 1 addition & 0 deletions packages/extension/src/libs/networks-state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface NetworkStorageElement {

export interface IState {
networks: NetworkStorageElement[];
newNetworksVersion: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ const inputAmount = (inputAmount: string) => {
}
const inputAmountBn = new BigNumber(inputAmount);
isMaxSelected.value = false;
amount.value = inputAmountBn.lt(0) ? "0" : inputAmountBn.toFixed();
amount.value = inputAmountBn.lt(0) ? "0" : inputAmount;
};
const toggleSelectFee = () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/extension/src/providers/common/libs/new-features.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { NetworkNames } from "@enkryptcom/types";

const newNetworks = [NetworkNames.Kadena, NetworkNames.Amplitude];
const newSwaps = [NetworkNames.MaticZK, NetworkNames.Arbitrum];

export { newNetworks, newSwaps };
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<input
ref="inputRef"
v-model="amount"
type="number"
type="text"
placeholder="0"
:style="{ color: !hasEnoughBalance ? 'red' : 'black' }"
@keypress="onlyNumber"
@focus="changeFocus"
@blur="changeFocus"
/>
Expand All @@ -31,7 +32,7 @@ import SwitchArrowIcon from "@action/icons/send/switch-arrow-icon.vue";
import BigNumber from "bignumber.js";
const emit = defineEmits<{
(e: "update:inputAmount", address: string): void;
(e: "update:inputAmount", value: string): void;
(e: "update:inputSetMax"): void;
}>();
Expand Down Expand Up @@ -64,10 +65,18 @@ const fiatEquivalent = computed(() => {
const amount = computed({
get: () => props.amount,
set: (value) => {
emit("update:inputAmount", value.toString());
let fValue = value.toString();
if (fValue === ".") fValue = "0.";
emit("update:inputAmount", fValue);
},
});
const onlyNumber = ($event: KeyboardEvent) => {
const keyCode = $event.keyCode ? $event.keyCode : $event.which;
if ((keyCode < 48 || keyCode > 57) && keyCode !== 46) {
$event.preventDefault();
}
};
const changeFocus = () => {
isFocus.value = !isFocus.value;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ const inputAmount = (inputAmount: string) => {
}
const inputAmountBn = new BigNumber(inputAmount);
isMaxSelected.value = false;
amount.value = inputAmountBn.lt(0) ? "0" : inputAmountBn.toFixed();
amount.value = inputAmountBn.lt(0) ? "0" : inputAmount;
if (isInputsValid.value) {
updateTransactionFees(Tx.value);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@

<send-input-amount
:amount="amount"
:show-max="true"
:fiat-value="selectedAsset.price"
:is-valid="fieldsValidation.amount"
:has-enough-balance="fieldsValidation.amount"
@update:input-amount="inputAmount"
@update:input-set-max="setSendMax"
/>
Expand Down Expand Up @@ -103,7 +104,7 @@ import SendContactsList from "./components/send-contacts-list.vue";
import SendFromContactsList from "./components/send-from-contacts-list.vue";
import SendTokenSelect from "./components/send-token-select.vue";
import AssetsSelectList from "@action/views/assets-select-list/index.vue";
import SendInputAmount from "./components/send-input-amount.vue";
import SendInputAmount from "@/providers/common/ui/send-transaction/send-input-amount.vue";
import SendFeeSelect from "./components/send-fee-select.vue";
import SendAlert from "./components/send-alert.vue";
import BaseButton from "@action/components/base-button/index.vue";
Expand Down Expand Up @@ -399,9 +400,13 @@ const selectToken = (token: KDAToken | Partial<KDAToken>) => {
isOpenSelectToken.value = false;
};
const inputAmount = (number: string | undefined) => {
const inputAmount = (inputAmount: string) => {
if (inputAmount === "") {
inputAmount = "0";
}
const inputAmountBn = new BigNumber(inputAmount);
sendMax.value = false;
amount.value = number ? (parseFloat(number) < 0 ? "" : number) : number;
amount.value = inputAmountBn.lt(0) ? "0" : inputAmount;
};
const sendButtonTitle = computed(() => {
Expand Down
Loading

1 comment on commit 0676512

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.