Skip to content

Commit

Permalink
fix: send balance error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
NickKelly1 committed Nov 27, 2024
2 parents 86fcadc + d3eab40 commit 45b17a9
Show file tree
Hide file tree
Showing 27 changed files with 717 additions and 95 deletions.
86 changes: 70 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,82 @@ Enkrypt is a web3 wallet built from the ground up to support the multi-chain fut
## Currently Supported Chains

- Ethereum
- Polygon
- BNB Smart Chain
- Moonbeam
- Moonriver
- Karura EVM
- Ethereum Classic
- Polkadot
- Kusama
- Edgeware
- Bitcoin
- Solana
- Acala
- Karura
- TomoChain
- Amplitude
- Arbitrum
- Gnosis
- Arbitrum Nova
- Arthera
- Astar
- Astar EVM
- Aurora
- Avalanche
- Base
- Bifrost
- Bifrost (Kusama)
- Binance Smart Chain
- Bitcoin Testnet
- Bitrock
- Blast
- Caga Ankara Testnet
- Canto
- Celo
- Degen
- Dogecoin
- Edgeware
- Edgeware EVM
- Ethereum Classic
- Fantom
- Forma
- Fraxtal
- 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)
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/libs/cache-fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const cacheFetch = async (
.then(json => {
const jsondata = options.postProcess ? options.postProcess(json) : json;
const jsonstring = JSON.stringify(jsondata);
if (!jsonstring.includes('error')) {
if (!json.error) {
const store: StoredData = {
timestamp: new Date().getTime(),
data: jsonstring,
Expand Down
40 changes: 39 additions & 1 deletion packages/extension/src/libs/tokens-state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<boolean> {
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];
}

await this.storage.set(StorageKeys.customTokens, state);
return true;
}
}
}

return false;
}

async getTokensByNetwork(chainName: NetworkNames): Promise<CustomToken[]> {
const state: IState | null = await this.storage.get(
StorageKeys.customTokens,
Expand Down
14 changes: 14 additions & 0 deletions packages/extension/src/libs/utils/number-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,19 @@ 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));
};


export {
formatIntegerToString,
formatIntegerValue,
Expand All @@ -526,4 +539,5 @@ export {
formatPercentageValue,
formatGasValue,
toBNSafe,
isNumericPositive
};
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const NetworkEndpoints: Record<string, string> = {
[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 };
25 changes: 25 additions & 0 deletions packages/extension/src/providers/ethereum/networks/bitrock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import icon from './icons/bitrock.svg';
import { CoingeckoPlatform, NetworkNames } from '@enkryptcom/types';
import { EvmNetwork, EvmNetworkOptions } from '../types/evm-network';
import wrapActivityHandler from '@/libs/activity-state/wrap-activity-handler';

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,
coingeckoID: 'bitrock',
coingeckoPlatform: CoingeckoPlatform.Bitrock,
activityHandler: wrapActivityHandler(() => Promise.resolve([])),
};

const bitrock = new EvmNetwork(bitrockOptions);

export default bitrock;
26 changes: 26 additions & 0 deletions packages/extension/src/providers/ethereum/networks/fraxtal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import icon from './icons/fraxtal.svg';
import { CoingeckoPlatform, NetworkNames } from '@enkryptcom/types';
import { EvmNetwork, EvmNetworkOptions } from '../types/evm-network';
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,
coingeckoID: 'fraxtal',
coingeckoPlatform: CoingeckoPlatform.Fraxtal,
activityHandler: wrapActivityHandler(EtherscanActivity),
};

const fraxtal = new EvmNetwork(fraxtalOptions);

export default fraxtal;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/extension/src/providers/ethereum/networks/index.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ import proofOfPlayApexNode from './pop-apex';
import scrollNode from './scroll';
import cotiDevnetNode from './coti-devnet';
import holeskyNode from './holesky';
import bitrockNode from './bitrock';
import fraxtalNode from './fraxtal';

export default {
sepolia: sepoliaNode,
Expand Down Expand Up @@ -131,4 +133,6 @@ export default {
scroll: scrollNode,
cotiDevnet: cotiDevnetNode,
holesky: holeskyNode,
bitrock: bitrockNode,
frax: fraxtalNode,
};
Loading

0 comments on commit 45b17a9

Please sign in to comment.