From aabea15a18dfad2d9dfba842a8d866dd429256cb Mon Sep 17 00:00:00 2001 From: Jan Turk Date: Fri, 4 Oct 2024 00:56:06 +0200 Subject: [PATCH 01/33] Add Fraxtal network --- .../providers/etherscan/configs.ts | 1 + .../libs/assets-handlers/assetinfo-mew.ts | 4 +++ .../libs/assets-handlers/token-lists.ts | 1 + .../assets-handlers/types/tokenbalance-mew.ts | 3 +- .../providers/ethereum/networks/fraxtal.ts | 29 +++++++++++++++++ .../ethereum/networks/icons/fraxtal.svg | 32 +++++++++++++++++++ .../src/providers/ethereum/networks/index.ts | 2 ++ packages/types/src/networks.ts | 2 ++ 8 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 packages/extension/src/providers/ethereum/networks/fraxtal.ts create mode 100755 packages/extension/src/providers/ethereum/networks/icons/fraxtal.svg diff --git a/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts b/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts index 64aa911bc..c904df373 100644 --- a/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts +++ b/packages/extension/src/providers/ethereum/libs/activity-handlers/providers/etherscan/configs.ts @@ -68,6 +68,7 @@ const NetworkEndpoints: Record = { [NetworkNames.Mode]: "https://explorer.mode.network/", [NetworkNames.ProofOfPlayApex]: "https://explorer.apex.proofofplay.com/", [NetworkNames.Scroll]: "https://api.scrollscan.com/", + [NetworkNames.Fraxtal]: "https://api.fraxscan.com/", }; export { NetworkEndpoints }; diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts index 27e45a6f3..24399d099 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/assetinfo-mew.ts @@ -175,6 +175,10 @@ const supportedNetworks: Record = { tbName: "rari", cgPlatform: undefined, }, + [NetworkNames.Fraxtal]: { + tbName: "frax", + cgPlatform: CoingeckoPlatform.Fraxtal, + }, }; const getTokens = ( diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts index d9ab4eb20..c1ddbb282 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts @@ -40,6 +40,7 @@ const TokenList: Record = { [NetworkNames.OpBNB]: `https://tokens.coingecko.com/${CoingeckoPlatform.OpBNB}/all.json`, [NetworkNames.Scroll]: `https://tokens.coingecko.com/${CoingeckoPlatform.Scroll}/all.json`, [NetworkNames.Rari]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/tokenlists/rari.json`, + [NetworkNames.Fraxtal]: `https://tokens.coingecko.com/${CoingeckoPlatform.Fraxtal}/all.json`, }; const getKnownNetworkTokens = async ( diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts index 35e0adb59..c0b1dde97 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/types/tokenbalance-mew.ts @@ -62,4 +62,5 @@ export type SupportedNetworkNames = | NetworkNames.Mode | NetworkNames.OpBNB | NetworkNames.Scroll - | NetworkNames.Rari; + | NetworkNames.Rari + | NetworkNames.Fraxtal; diff --git a/packages/extension/src/providers/ethereum/networks/fraxtal.ts b/packages/extension/src/providers/ethereum/networks/fraxtal.ts new file mode 100644 index 000000000..7fb84abb7 --- /dev/null +++ b/packages/extension/src/providers/ethereum/networks/fraxtal.ts @@ -0,0 +1,29 @@ +import { CoingeckoPlatform, NetworkNames } from "@enkryptcom/types"; +import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network"; +import assetsInfoHandler from "@/providers/ethereum/libs/assets-handlers/assetinfo-mew"; +import mewNFTHandler from "@/libs/nft-handlers/mew"; +import { EtherscanActivity } from "../libs/activity-handlers"; +import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler"; + +const fraxtalOptions: EvmNetworkOptions = { + name: NetworkNames.Fraxtal, + name_long: "Fraxtal", + homePage: "https://www.frax.com/", + blockExplorerTX: "https://fraxscan.com/tx/[[txHash]]", + blockExplorerAddr: "https://fraxscan.com/address/[[address]]", + chainID: "0xfc", + isTestNetwork: false, + currencyName: "frxETH", + currencyNameLong: "Frax Ether", + node: "https://rpc.frax.com", + icon: require("./icons/fraxtal.svg"), + coingeckoID: "fraxtal", + coingeckoPlatform: CoingeckoPlatform.Fraxtal, + NFTHandler: mewNFTHandler, + assetsInfoHandler, + activityHandler: wrapActivityHandler(EtherscanActivity), +}; + +const fraxtal = new EvmNetwork(fraxtalOptions); + +export default fraxtal; diff --git a/packages/extension/src/providers/ethereum/networks/icons/fraxtal.svg b/packages/extension/src/providers/ethereum/networks/icons/fraxtal.svg new file mode 100755 index 000000000..158a6ac8d --- /dev/null +++ b/packages/extension/src/providers/ethereum/networks/icons/fraxtal.svg @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + diff --git a/packages/extension/src/providers/ethereum/networks/index.ts b/packages/extension/src/providers/ethereum/networks/index.ts index cd771d291..090a36b88 100644 --- a/packages/extension/src/providers/ethereum/networks/index.ts +++ b/packages/extension/src/providers/ethereum/networks/index.ts @@ -57,6 +57,7 @@ import opbnbNode from "./op-bnb"; import palmNode from "./palm"; import proofOfPlayApexNode from "./pop-apex"; import scrollNode from "./scroll"; +import fraxtalNode from "./fraxtal"; export default { sepolia: sepoliaNode, @@ -127,4 +128,5 @@ export default { palm: palmNode, popApex: proofOfPlayApexNode, scroll: scrollNode, + frax: fraxtalNode, }; diff --git a/packages/types/src/networks.ts b/packages/types/src/networks.ts index 235ff9bf3..fb41cb5fd 100644 --- a/packages/types/src/networks.ts +++ b/packages/types/src/networks.ts @@ -91,6 +91,7 @@ export enum NetworkNames { ProofOfPlayApex = "ProofOfPlayApex", Scroll = "scroll", Rari = "rari", + Fraxtal = "fraxtal", } export enum CoingeckoPlatform { @@ -146,4 +147,5 @@ export enum CoingeckoPlatform { Mode = "mode", OpBNB = "opbnb", Scroll = "scroll", + Fraxtal = "fraxtal", } From 7657c10183445d22ec2fe32f322a571f9e5378ee Mon Sep 17 00:00:00 2001 From: Mdd 0x Date: Wed, 30 Oct 2024 20:11:06 +0700 Subject: [PATCH 02/33] Add Bitrock Chain --- .../providers/ethereum/networks/bitrock.ts | 22 ++++++++ .../ethereum/networks/icons/bitrock.svg | 55 +++++++++++++++++++ .../src/providers/ethereum/networks/index.ts | 2 + packages/types/src/networks.ts | 1 + 4 files changed, 80 insertions(+) create mode 100755 packages/extension/src/providers/ethereum/networks/bitrock.ts create mode 100755 packages/extension/src/providers/ethereum/networks/icons/bitrock.svg mode change 100644 => 100755 packages/extension/src/providers/ethereum/networks/index.ts mode change 100644 => 100755 packages/types/src/networks.ts diff --git a/packages/extension/src/providers/ethereum/networks/bitrock.ts b/packages/extension/src/providers/ethereum/networks/bitrock.ts new file mode 100755 index 000000000..3849e554b --- /dev/null +++ b/packages/extension/src/providers/ethereum/networks/bitrock.ts @@ -0,0 +1,22 @@ +import { NetworkNames } from "@enkryptcom/types"; +import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network"; + +const bitrockOptions: EvmNetworkOptions = { + name: NetworkNames.Bitrock, + name_long: "Bitrock Chain", + homePage: "https://bit-rock.io/", + blockExplorerTX: "https://explorer.bit-rock.io/tx/[[txHash]]", + blockExplorerAddr: "https://explorer.bit-rock.io/address/[[address]]", + chainID: "0x1c03", + isTestNetwork: false, + currencyName: "BROCK", + currencyNameLong: "Bitrock", + node: "https://brockrpc.io", + icon: require("./icons/bitrock.svg"), + coingeckoID: "bitrock", + activityHandler: () => Promise.resolve([]), +}; + +const bitrock = new EvmNetwork(bitrockOptions); + +export default bitrock; diff --git a/packages/extension/src/providers/ethereum/networks/icons/bitrock.svg b/packages/extension/src/providers/ethereum/networks/icons/bitrock.svg new file mode 100755 index 000000000..5bc9dd43a --- /dev/null +++ b/packages/extension/src/providers/ethereum/networks/icons/bitrock.svg @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/extension/src/providers/ethereum/networks/index.ts b/packages/extension/src/providers/ethereum/networks/index.ts old mode 100644 new mode 100755 index c5197358f..c925578f1 --- a/packages/extension/src/providers/ethereum/networks/index.ts +++ b/packages/extension/src/providers/ethereum/networks/index.ts @@ -59,6 +59,7 @@ import proofOfPlayApexNode from "./pop-apex"; import scrollNode from "./scroll"; import cotiDevnetNode from "./coti-devnet"; import holeskyNode from "./holesky"; +import bitrockNode from "./bitrock"; export default { sepolia: sepoliaNode, @@ -131,4 +132,5 @@ export default { scroll: scrollNode, cotiDevnet: cotiDevnetNode, holesky: holeskyNode, + bitrock: bitrockNode, }; diff --git a/packages/types/src/networks.ts b/packages/types/src/networks.ts old mode 100644 new mode 100755 index 3b5d00cc2..5ea90965b --- a/packages/types/src/networks.ts +++ b/packages/types/src/networks.ts @@ -94,6 +94,7 @@ export enum NetworkNames { Rari = "rari", CotiDevnet = "CotiDevnet", Holesky = "HOLESKY", + Bitrock = "bitrock", } export enum CoingeckoPlatform { From 88951a10e90b4f96a2576798e893141d24ff2ed2 Mon Sep 17 00:00:00 2001 From: kealiiokalani <113649059+kealiiokalani@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:28:41 -0700 Subject: [PATCH 03/33] Add Bitcoin and Solana to Currently Supported Chains Add Bitcoin and Solana to Currently Supported Chains --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c5896b7b4..6ba3bd167 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ Enkrypt is a web3 wallet built from the ground up to support the multi-chain fut ## Currently Supported Chains - Ethereum +- Bitcoin +- Solana - Polygon - BNB Smart Chain - Moonbeam From 2d4d227874db0e73b89cdaf5872c09b92b732409 Mon Sep 17 00:00:00 2001 From: kealiiokalani <113649059+kealiiokalani@users.noreply.github.com> Date: Thu, 31 Oct 2024 14:02:03 -0700 Subject: [PATCH 04/33] Add new Enkrypt chains Added all Enkrypt current chains in alphabetical order --- README.md | 82 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 6ba3bd167..70c763cbd 100644 --- a/README.md +++ b/README.md @@ -34,28 +34,78 @@ Enkrypt is a web3 wallet built from the ground up to support the multi-chain fut - Ethereum - Bitcoin - Solana -- Polygon -- BNB Smart Chain -- Moonbeam -- Moonriver -- Karura EVM -- Ethereum Classic -- Polkadot -- Kusama -- Edgeware - Acala -- Karura -- TomoChain +- Amplitude - Arbitrum -- Gnosis +- Arbitrum Nova +- Arthera +- Astar +- Astar EVM +- Aurora - Avalanche +- Base +- Bifrost +- Bifrost (Kusama) +- Binance Smart Chain +- Bitcoin Testnet +- Blast +- Caga Ankara Testnet +- Canto +- Celo +- Degen +- Dogecoin +- Edgeware +- Edgeware EVM +- Ethereum Classic - Fantom +- Forma +- Gnosis +- Godwoken +- Goerli +- Ham Chain +- Immutable zkEVM +- Kadena +- Karura +- Karura EVM - Klaytn -- Aurora -- Ontology +- Kusama +- Linea +- Litecoin +- Manta Pacific +- Mode +- Moonbeam +- Moonriver +- OKX Chain +- Ontology EVM +- Opal +- opBNB +- Optimism +- Palm Network +- Pendulum +- Polkadot +- Polygon +- Polygon zkEVM +- Proof of Play Apex - Puppy Net -- Arthera -- Caga Ankara Testnet +- Quartz +- RARI Chain +- Rollux +- Rootstock +- Sanko Chain +- Scroll +- Shibarium +- Shiden +- Shiden EVM +- Sepolia +- Syscoin +- Telos EVM +- Unique +- Vara Network +- Viction +- Westend +- ZChains +- zkSync +- zkSync Goerli - More coming soon! Looking to add your project? [Contact us!](https://mewwallet.typeform.com/enkrypt-inquiry?typeform-source=www.enkrypt.com) From f3a4aaf0f0bd8204880a09d7bffef383d2fd6d13 Mon Sep 17 00:00:00 2001 From: Mdd 0x Date: Fri, 1 Nov 2024 16:56:29 +0700 Subject: [PATCH 05/33] add bitrock coingecko platform on assets handlers token list --- .../src/providers/ethereum/libs/assets-handlers/token-lists.ts | 1 + packages/extension/src/providers/ethereum/networks/bitrock.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts b/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts index ffe903ab8..201fd9cca 100644 --- a/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts +++ b/packages/extension/src/providers/ethereum/libs/assets-handlers/token-lists.ts @@ -41,6 +41,7 @@ const TokenList: Record = { [NetworkNames.OpBNB]: `https://tokens.coingecko.com/${CoingeckoPlatform.OpBNB}/all.json`, [NetworkNames.Scroll]: `https://tokens.coingecko.com/${CoingeckoPlatform.Scroll}/all.json`, [NetworkNames.Rari]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/tokenlists/rari.json`, + [NetworkNames.Bitrock]: `https://tokens.coingecko.com/${CoingeckoPlatform.Bitrock}/all.json`, }; const getKnownNetworkTokens = async ( diff --git a/packages/extension/src/providers/ethereum/networks/bitrock.ts b/packages/extension/src/providers/ethereum/networks/bitrock.ts index 3849e554b..e2013013a 100755 --- a/packages/extension/src/providers/ethereum/networks/bitrock.ts +++ b/packages/extension/src/providers/ethereum/networks/bitrock.ts @@ -1,3 +1,4 @@ +import { CoingeckoPlatform, NetworkNames } from "@enkryptcom/types"; import { NetworkNames } from "@enkryptcom/types"; import { EvmNetwork, EvmNetworkOptions } from "../types/evm-network"; @@ -14,6 +15,7 @@ const bitrockOptions: EvmNetworkOptions = { node: "https://brockrpc.io", icon: require("./icons/bitrock.svg"), coingeckoID: "bitrock", + coingeckoPlatform: CoingeckoPlatform.Bitrock, activityHandler: () => Promise.resolve([]), }; From 6f1d4c915b0fdfbe39f9588f27b53f80cfbbb46b Mon Sep 17 00:00:00 2001 From: Gamaliel Padillo Date: Wed, 13 Nov 2024 16:42:17 -0800 Subject: [PATCH 06/33] fix: invalid value on send --- .../providers/ethereum/ui/send-transaction/index.vue | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue index d042451b8..08a70a349 100644 --- a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue @@ -219,6 +219,11 @@ const hasEnoughBalance = computed(() => { return false; } + // check if valid sendAmount.value + if (!isNumeric(sendAmount.value)) { + return false; + } + return toBN(selectedAsset.value.balance ?? '0').gte( toBN(toBase(sendAmount.value ?? '0', selectedAsset.value.decimals!)), ); @@ -345,8 +350,9 @@ const nativeBalanceAfterTransaction = computed(() => { let endingAmount = toBN(nativeBalance.value); if (selectedAsset.value.contract === NATIVE_TOKEN_ADDRESS) { + const locAmount = isNumeric(amount.value) ? amount.value : '0'; const rawAmount = toBN( - toBase(amount.value, selectedAsset.value.decimals!), + toBase(locAmount ?? '0', selectedAsset.value.decimals!), ); endingAmount = endingAmount.sub(rawAmount); } @@ -531,6 +537,10 @@ const close = () => { router.go(-1); }; +const isNumeric = (value: string) => { + return /^-?\d+(\.\d+)?$/.test(value); +}; + const assetMaxValue = computed(() => { if (!isSendToken.value) { return '0'; From cece01e30d9bb83e54813108cd8a0fc49a1fba80 Mon Sep 17 00:00:00 2001 From: Gamaliel Padillo Date: Wed, 13 Nov 2024 16:52:31 -0800 Subject: [PATCH 07/33] fix: only allow positive numbers --- .../src/providers/ethereum/ui/send-transaction/index.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue index 08a70a349..92f700226 100644 --- a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue @@ -220,7 +220,7 @@ const hasEnoughBalance = computed(() => { } // check if valid sendAmount.value - if (!isNumeric(sendAmount.value)) { + if (!isNumericPositive(sendAmount.value)) { return false; } @@ -350,7 +350,7 @@ const nativeBalanceAfterTransaction = computed(() => { let endingAmount = toBN(nativeBalance.value); if (selectedAsset.value.contract === NATIVE_TOKEN_ADDRESS) { - const locAmount = isNumeric(amount.value) ? amount.value : '0'; + const locAmount = isNumericPositive(amount.value) ? amount.value : '0'; const rawAmount = toBN( toBase(locAmount ?? '0', selectedAsset.value.decimals!), ); @@ -537,8 +537,8 @@ const close = () => { router.go(-1); }; -const isNumeric = (value: string) => { - return /^-?\d+(\.\d+)?$/.test(value); +const isNumericPositive = (value: string) => { + return /^\d+(\.\d+)?$/.test(value); }; const assetMaxValue = computed(() => { From 4a368ff385380409eef9461d25ca5778086b925a Mon Sep 17 00:00:00 2001 From: Gamaliel Padillo Date: Wed, 13 Nov 2024 17:04:02 -0800 Subject: [PATCH 08/33] fix: add coderabbit recomendations --- .../src/providers/ethereum/ui/send-transaction/index.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue index 92f700226..2859204c9 100644 --- a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue @@ -538,7 +538,9 @@ const close = () => { }; const isNumericPositive = (value: string) => { - return /^\d+(\.\d+)?$/.test(value); + if (/^\d+(\.\d+)?$/.test(value)) return false; + const num = BigNumber(value); + return !num.isNaN() && num.isPositive() && num.lt(new BigNumber(2).pow(256)); }; const assetMaxValue = computed(() => { From 31bb64b48f37f2556f786ef56fddf4429ed72796 Mon Sep 17 00:00:00 2001 From: Gamaliel Padillo Date: Thu, 14 Nov 2024 15:10:09 -0800 Subject: [PATCH 09/33] fix: remove regex and use bignum, go through all send ui --- .../src/libs/utils/number-formatter.ts | 7 +++++++ .../bitcoin/ui/send-transaction/index.vue | 9 +++++++- .../ethereum/ui/send-transaction/index.vue | 12 +++++------ .../kadena/ui/send-transaction/index.vue | 12 ++++++++++- .../polkadot/ui/send-transaction/index.vue | 21 +++++++++++++++---- 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/packages/extension/src/libs/utils/number-formatter.ts b/packages/extension/src/libs/utils/number-formatter.ts index eb0111d7a..923c5dfaf 100644 --- a/packages/extension/src/libs/utils/number-formatter.ts +++ b/packages/extension/src/libs/utils/number-formatter.ts @@ -517,6 +517,12 @@ const toBNSafe = (number: number) => { return toBN(new BigNumber(number).toFixed(0)); }; +const isNumericPositive = (value: string) => { + const num = BigNumber(value); + return !num.isNaN() && num.isPositive() && num.lt(new BigNumber(2).pow(256)); +}; + + export { formatIntegerToString, formatIntegerValue, @@ -526,4 +532,5 @@ export { formatPercentageValue, formatGasValue, toBNSafe, + isNumericPositive }; 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 476e459be..410ee13fe 100644 --- a/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue @@ -149,7 +149,10 @@ import { BTCToken } from '../../types/btc-token'; import BigNumber from 'bignumber.js'; import { defaultGasCostVals } from '@/providers/common/libs/default-vals'; import { fromBase, toBase, isValidDecimals } from '@enkryptcom/utils'; -import { formatFloatingPointValue } from '@/libs/utils/number-formatter'; +import { + formatFloatingPointValue, + isNumericPositive, +} from '@/libs/utils/number-formatter'; import { routes as RouterNames } from '@/ui/action/router'; import getUiPath from '@/libs/utils/get-ui-path'; import Browser from 'webextension-polyfill'; @@ -218,6 +221,10 @@ onMounted(async () => { }); const nativeBalanceAfterTransaction = computed(() => { + if (!isNumericPositive(sendAmount.value)) { + return toBN(0); + } + if ( selectedAsset.value && isValidDecimals(sendAmount.value, selectedAsset.value.decimals!) diff --git a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue index 2859204c9..5d638b745 100644 --- a/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/ethereum/ui/send-transaction/index.vue @@ -168,7 +168,10 @@ import erc20 from '../../libs/abi/erc20'; import erc721 from '../../libs/abi/erc721'; import erc1155 from '../../libs/abi/erc1155'; import { SendTransactionDataType, VerifyTransactionParams } from '../types'; -import { formatFloatingPointValue } from '@/libs/utils/number-formatter'; +import { + formatFloatingPointValue, + isNumericPositive, +} from '@/libs/utils/number-formatter'; import { routes as RouterNames } from '@/ui/action/router'; import getUiPath from '@/libs/utils/get-ui-path'; import Browser from 'webextension-polyfill'; @@ -494,6 +497,7 @@ const isInputsValid = computed(() => { } if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) return false; if (gasCostValues.value.REGULAR.nativeValue === '0') return false; + if (!isNumericPositive(sendAmount.value)) return false; return true; }); @@ -537,12 +541,6 @@ const close = () => { router.go(-1); }; -const isNumericPositive = (value: string) => { - if (/^\d+(\.\d+)?$/.test(value)) return false; - const num = BigNumber(value); - return !num.isNaN() && num.isPositive() && num.lt(new BigNumber(2).pow(256)); -}; - const assetMaxValue = computed(() => { if (!isSendToken.value) { return '0'; diff --git a/packages/extension/src/providers/kadena/ui/send-transaction/index.vue b/packages/extension/src/providers/kadena/ui/send-transaction/index.vue index 4603cb527..6fd9782be 100644 --- a/packages/extension/src/providers/kadena/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/kadena/ui/send-transaction/index.vue @@ -110,7 +110,10 @@ import BaseButton from '@action/components/base-button/index.vue'; import { AccountsHeaderData } from '@action/types/account'; import { GasFeeInfo } from '@/providers/ethereum/ui/types'; import { toBN } from 'web3-utils'; -import { formatFloatingPointValue } from '@/libs/utils/number-formatter'; +import { + formatFloatingPointValue, + isNumericPositive, +} from '@/libs/utils/number-formatter'; import { fromBase, toBase, isValidDecimals } from '@enkryptcom/utils'; import BigNumber from 'bignumber.js'; import { VerifyTransactionParams } from '../types'; @@ -235,6 +238,13 @@ const validateFields = async () => { return; } + if (!isNumericPositive(amount.value)) { + console.log('amount', amount.value, !isNumericPositive(amount.value)); + fieldsValidation.value.amount = false; + errorMsg.value = 'Invalid amount. Amount has to be greater than 0'; + return; + } + rawAmount = toBN( toBase(amount.value.toString(), selectedAsset.value.decimals!), ); diff --git a/packages/extension/src/providers/polkadot/ui/send-transaction/index.vue b/packages/extension/src/providers/polkadot/ui/send-transaction/index.vue index b11d7a11d..ce3bf47fa 100644 --- a/packages/extension/src/providers/polkadot/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/polkadot/ui/send-transaction/index.vue @@ -121,7 +121,10 @@ import { AccountsHeaderData } from '@action/types/account'; import { GasFeeInfo } from '@/providers/ethereum/ui/types'; import { SubstrateNetwork } from '../../types/substrate-network'; import { toBN } from 'web3-utils'; -import { formatFloatingPointValue } from '@/libs/utils/number-formatter'; +import { + formatFloatingPointValue, + isNumericPositive, +} from '@/libs/utils/number-formatter'; import { fromBase, toBase, isValidDecimals } from '@enkryptcom/utils'; import BigNumber from 'bignumber.js'; import { AlertType, VerifyTransactionParams } from '../types'; @@ -138,6 +141,7 @@ import { GenericNameResolver, CoinType } from '@/libs/name-resolver'; import { trackSendEvents } from '@/libs/metrics'; import { SendEventType } from '@/libs/metrics/types'; import { BNType } from '@/providers/common/types'; +import { a } from 'vitest/dist/chunks/suite.B2jumIFP.js'; const props = defineProps({ network: { @@ -195,7 +199,12 @@ const edWarn = computed(() => { } const rawAmount = toBN( - toBase(amount.value.toString(), selectedAsset.value.decimals ?? 0), + toBase( + isNumericPositive(amount.value.toString()) + ? amount.value.toString() + : '0', + selectedAsset.value.decimals ?? 0, + ), ); const ed = selectedAsset.value.existentialDeposit ?? toBN(0); const userBalance = toBN(selectedAsset.value.balance ?? 0); @@ -246,7 +255,9 @@ const validateFields = async () => { let rawAmount = toBN( toBase( - amount.value ? amount.value.toString() : '0', + amount.value && isNumericPositive(amount.value.toString()) + ? amount.value.toString() + : '0', selectedAsset.value.decimals!, ), ); @@ -448,9 +459,10 @@ const destinationBalanceCheck = computed(() => { if (selectedAsset.value.symbol !== accountAssets.value[0].symbol) return destinationHasEnough.value; else { + const checkedValue = amount.value?.toString() ?? '0'; const rawAmount = toBN( toBase( - amount.value?.toString() ?? '0', + isNumericPositive(checkedValue) ? checkedValue : '0', selectedAsset.value.decimals ?? 0, ), ); @@ -475,6 +487,7 @@ const isDisabled = computed(() => { if ( amount.value !== undefined && amount.value !== '' && + isNumericPositive(amount.value) && hasEnough.value && addressIsValid && !edWarn.value && From e0161b0607838656bdf1b5d19aa6e42193c40fcf Mon Sep 17 00:00:00 2001 From: Gamaliel Padillo Date: Thu, 14 Nov 2024 15:49:15 -0800 Subject: [PATCH 10/33] devop: add code rabbit recs --- packages/extension/src/libs/utils/number-formatter.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/extension/src/libs/utils/number-formatter.ts b/packages/extension/src/libs/utils/number-formatter.ts index 923c5dfaf..a33f61fb7 100644 --- a/packages/extension/src/libs/utils/number-formatter.ts +++ b/packages/extension/src/libs/utils/number-formatter.ts @@ -517,7 +517,14 @@ const toBNSafe = (number: number) => { return toBN(new BigNumber(number).toFixed(0)); }; +/** + * Validates if a string represents a positive numeric value less than 2^256. + * Used for validating transaction amounts across different blockchain implementations. + * @param {string} value - The string value to validate + * @returns {boolean} - True if the value is a valid positive number within bounds + */ const isNumericPositive = (value: string) => { + if (!value?.trim()) return false; const num = BigNumber(value); return !num.isNaN() && num.isPositive() && num.lt(new BigNumber(2).pow(256)); }; From 97835870e9312f0bd293dbbac915ca7e66b90924 Mon Sep 17 00:00:00 2001 From: Gamaliel Padillo Date: Thu, 14 Nov 2024 16:55:18 -0800 Subject: [PATCH 11/33] devop: remove weird import --- .../src/providers/polkadot/ui/send-transaction/index.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/extension/src/providers/polkadot/ui/send-transaction/index.vue b/packages/extension/src/providers/polkadot/ui/send-transaction/index.vue index ce3bf47fa..bae45e7bc 100644 --- a/packages/extension/src/providers/polkadot/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/polkadot/ui/send-transaction/index.vue @@ -141,7 +141,6 @@ import { GenericNameResolver, CoinType } from '@/libs/name-resolver'; import { trackSendEvents } from '@/libs/metrics'; import { SendEventType } from '@/libs/metrics/types'; import { BNType } from '@/providers/common/types'; -import { a } from 'vitest/dist/chunks/suite.B2jumIFP.js'; const props = defineProps({ network: { From 299aae228bac53d5d581195cfc96dfa135bd1623 Mon Sep 17 00:00:00 2001 From: Gamaliel Padillo Date: Fri, 15 Nov 2024 11:42:01 -0800 Subject: [PATCH 12/33] fix: remove console.log --- .../extension/src/providers/kadena/ui/send-transaction/index.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/extension/src/providers/kadena/ui/send-transaction/index.vue b/packages/extension/src/providers/kadena/ui/send-transaction/index.vue index 6fd9782be..e1bd7305c 100644 --- a/packages/extension/src/providers/kadena/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/kadena/ui/send-transaction/index.vue @@ -239,7 +239,6 @@ const validateFields = async () => { } if (!isNumericPositive(amount.value)) { - console.log('amount', amount.value, !isNumericPositive(amount.value)); fieldsValidation.value.amount = false; errorMsg.value = 'Invalid amount. Amount has to be greater than 0'; return; From 0e46fd696e052e0d27e81b5ed7b9b2d6399f08e8 Mon Sep 17 00:00:00 2001 From: Gamaliel Padillo Date: Fri, 15 Nov 2024 12:45:21 -0800 Subject: [PATCH 13/33] fix: custom token spacing, and overflow --- .../network-assets/components/custom-evm-token.vue | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/extension/src/ui/action/views/network-assets/components/custom-evm-token.vue b/packages/extension/src/ui/action/views/network-assets/components/custom-evm-token.vue index a1219e480..f1e8453cb 100644 --- a/packages/extension/src/ui/action/views/network-assets/components/custom-evm-token.vue +++ b/packages/extension/src/ui/action/views/network-assets/components/custom-evm-token.vue @@ -47,7 +47,14 @@ ).value : '~' }} - {{ tokenInfo.symbol }} + {{ + tokenInfo.symbol + }} + {{ + `${tokenInfo.symbol.slice(0, 12)}...` + }}

@@ -279,7 +286,7 @@ const addToken = async () => { .add-custom-token { width: 460px; - height: 568px; + height: 385px; box-sizing: border-box; position: relative; border-radius: 12px; @@ -422,10 +429,11 @@ const addToken = async () => { letter-spacing: 0.5px; color: @secondaryLabel; margin: 0; - width: 128px; + display: flex; span { font-variant: small-caps; + font-size: 12px; } } } From fd6b474924d77ed95f070e190fc565bbbab34764 Mon Sep 17 00:00:00 2001 From: Gamaliel Padillo Date: Tue, 19 Nov 2024 14:03:22 -0800 Subject: [PATCH 14/33] feat: add delete custom token and label warning --- .../extension/src/libs/tokens-state/index.ts | 40 ++++++++++++++- .../providers/ethereum/types/evm-network.ts | 5 +- .../action/views/asset-detail-view/index.vue | 26 +++++++++- .../components/network-assets-item.vue | 49 ++++++++++++++++++- .../ui/action/views/network-assets/index.vue | 5 ++ 5 files changed, 119 insertions(+), 6 deletions(-) diff --git a/packages/extension/src/libs/tokens-state/index.ts b/packages/extension/src/libs/tokens-state/index.ts index 919e28fed..52ad239e4 100644 --- a/packages/extension/src/libs/tokens-state/index.ts +++ b/packages/extension/src/libs/tokens-state/index.ts @@ -35,7 +35,7 @@ export class TokensState { if ( t.type === TokenType.ERC20 && (t as CustomErc20Token).address.toLowerCase() === - token.address.toLowerCase() + token.address.toLowerCase() ) { return false; } @@ -54,6 +54,44 @@ export class TokensState { return true; } + /** + * Remove a custom ERC20 token from a given network. + * Returns `true` if the token was removed and false otherwise. + * @param {NetworkNames} chainName - The name of the network the token is being removed from. + * @param {string} address - The address of the token being removed. + */ + async removeErc20Token( + chainName: NetworkNames, + address: string, + ): Promise { + const state: IState | null = await this.storage.get(StorageKeys.customTokens); + + if (state && state[chainName]) { + const tokens = state[chainName]; + + for (let i = 0; i < tokens!.length; i++) { + const token = tokens![i]; + + if ( + token.type === TokenType.ERC20 && + (token as CustomErc20Token).address.toLowerCase() === + address.toLowerCase() + ) { + tokens!.splice(i, 1); + + if (tokens!.length === 0) { + delete state[chainName]; + } + + this.storage.set(StorageKeys.customTokens, state); + return true; + } + } + } + + return false; + } + async getTokensByNetwork(chainName: NetworkNames): Promise { const state: IState | null = await this.storage.get( StorageKeys.customTokens, diff --git a/packages/extension/src/providers/ethereum/types/evm-network.ts b/packages/extension/src/providers/ethereum/types/evm-network.ts index c4897a4e3..10a4158f2 100644 --- a/packages/extension/src/providers/ethereum/types/evm-network.ts +++ b/packages/extension/src/providers/ethereum/types/evm-network.ts @@ -157,7 +157,7 @@ export class EvmNetwork extends BaseNetwork { decimals: this.decimals, sparkline: nativeMarketData ? new Sparkline(nativeMarketData.sparkline_in_24h.price, 25) - .dataValues + .dataValues : '', priceChangePercentage: nativeMarketData?.price_change_percentage_24h_in_currency ?? 0, @@ -197,7 +197,6 @@ export class EvmNetwork extends BaseNetwork { assets = [nativeAsset, ...assetInfos]; } - const customTokens = await tokensState .getTokensByNetwork(this.name) .then(tokens => { @@ -211,7 +210,7 @@ export class EvmNetwork extends BaseNetwork { a.contract && (token as CustomErc20Token).address && a.contract.toLowerCase() === - (token as CustomErc20Token).address.toLowerCase() + (token as CustomErc20Token).address.toLowerCase() ) { return false; } diff --git a/packages/extension/src/ui/action/views/asset-detail-view/index.vue b/packages/extension/src/ui/action/views/asset-detail-view/index.vue index 20c6aa868..1e484a44b 100644 --- a/packages/extension/src/ui/action/views/asset-detail-view/index.vue +++ b/packages/extension/src/ui/action/views/asset-detail-view/index.vue @@ -52,12 +52,24 @@

${{ token.balanceUSDf }}

+
+
+ + *Deleting custom token deletes it for the whole network. +
From a030dc6023a7f645c664af4d57314770714f089c Mon Sep 17 00:00:00 2001 From: Gamaliel Padillo Date: Wed, 20 Nov 2024 10:42:14 -0800 Subject: [PATCH 15/33] devop: add code rabbit suggestions --- .../components/network-assets-item.vue | 15 ++++++++++----- .../src/ui/action/views/network-assets/index.vue | 6 ++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/extension/src/ui/action/views/network-assets/components/network-assets-item.vue b/packages/extension/src/ui/action/views/network-assets/components/network-assets-item.vue index 8365fd959..a23da895c 100644 --- a/packages/extension/src/ui/action/views/network-assets/components/network-assets-item.vue +++ b/packages/extension/src/ui/action/views/network-assets/components/network-assets-item.vue @@ -134,11 +134,15 @@ const customTokens = ref([]); const tokenState = new TokensState(); const fetchCustomTokens = async () => { - return await tokenState.getTokensByNetwork(props.network.name).then(res => { - customTokens.value = res.filter( - (token): token is CustomErc20Token => 'address' in token, - ); - }); + try { + return await tokenState.getTokensByNetwork(props.network.name).then(res => { + customTokens.value = res.filter( + (token): token is CustomErc20Token => 'address' in token, + ); + }); + } catch { + customTokens.value = []; + } }; onMounted(async () => { @@ -146,6 +150,7 @@ onMounted(async () => { }); const isCustomToken = computed(() => { + if (!props.token.contract) return false; return customTokens.value.some( token => token.address.toLowerCase() === props.token.contract?.toLowerCase(), diff --git a/packages/extension/src/ui/action/views/network-assets/index.vue b/packages/extension/src/ui/action/views/network-assets/index.vue index 4aad72e73..87811e70c 100644 --- a/packages/extension/src/ui/action/views/network-assets/index.vue +++ b/packages/extension/src/ui/action/views/network-assets/index.vue @@ -147,11 +147,9 @@ const addCustomAsset = (asset: AssetsType) => { }); if (!existingAsset) { - assets.value = [...assets.value, asset]; + // refetches assets to update the custom token + updateAssets(); } - - // refetches assets to update the custom token - updateAssets(); }; From 37996b42832af23a397345f4c86fbaf94426ef72 Mon Sep 17 00:00:00 2001 From: Gamaliel Padillo Date: Wed, 20 Nov 2024 12:31:08 -0800 Subject: [PATCH 16/33] fix: error message for send when address has no balance for rent --- .../components/send-alert.vue | 53 +++++++++ .../solana/ui/send-transaction/index.vue | 109 +++++++++++++++--- 2 files changed, 147 insertions(+), 15 deletions(-) create mode 100644 packages/extension/src/providers/solana/ui/send-transaction/components/send-alert.vue diff --git a/packages/extension/src/providers/solana/ui/send-transaction/components/send-alert.vue b/packages/extension/src/providers/solana/ui/send-transaction/components/send-alert.vue new file mode 100644 index 000000000..ff3565591 --- /dev/null +++ b/packages/extension/src/providers/solana/ui/send-transaction/components/send-alert.vue @@ -0,0 +1,53 @@ + + + + + diff --git a/packages/extension/src/providers/solana/ui/send-transaction/index.vue b/packages/extension/src/providers/solana/ui/send-transaction/index.vue index 12b74be95..8468498a2 100644 --- a/packages/extension/src/providers/solana/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/solana/ui/send-transaction/index.vue @@ -93,18 +93,7 @@ :fee="gasCostValues[selectedFee]" /> - +
@@ -125,7 +114,7 @@