diff --git a/src/popup/locales/en.json b/src/popup/locales/en.json index e4e797bcf..af4d4f4c2 100644 --- a/src/popup/locales/en.json +++ b/src/popup/locales/en.json @@ -1238,6 +1238,7 @@ "required": "This field is required", "url": "Invalid URL", "address": "Enter valid blockchain address or .chain name", + "numeric": "The value should be a number", "name": "Enter valid .chain name", "nameRegisteredAddress": "Invalid address or .chain name", "nameUnregistered": "This name has already been registered.", @@ -1250,7 +1251,6 @@ "enoughAeSigner": "Insufficient balance on your signing account to propose a transaction", "maxLength": "The value should be no longer than {0} characters", "maxValue": "This field must be {0} or less", - "hexFormat": "The value should be in hex format", "maxRedeem": "Maximum redeemable amount is {0} AE.", "maxValueVault": "Amount is exceeding the vault's balance: {0}", "notToken": "Tokens are currently not allowed, please switch to AE", diff --git a/src/popup/plugins/veeValidate.ts b/src/popup/plugins/veeValidate.ts index eff959dcb..87b5442f4 100644 --- a/src/popup/plugins/veeValidate.ts +++ b/src/popup/plugins/veeValidate.ts @@ -1,5 +1,5 @@ import { defineRule } from 'vee-validate'; -import { required } from '@vee-validate/rules'; +import { numeric, required } from '@vee-validate/rules'; import BigNumber from 'bignumber.js'; import { debounce } from 'lodash-es'; import { isAddressValid, isNameValid } from '@aeternity/aepp-sdk'; @@ -32,6 +32,11 @@ defineRule( (value: string) => !value || isUrlValid(value) || tg('validation.url'), ); +defineRule( + 'numeric', + (value: string) => numeric(value) || tg('validation.numeric'), +); + defineRule( 'account', (value: string) => isAddressValid(value) || isNameValid(value) || tg('validation.address'), @@ -109,18 +114,6 @@ defineRule( }, ); -defineRule( - 'is_hex_format', - (value: string) => ( - ( - value?.toString()?.startsWith('0x') - && value.length >= 3 - && parseInt(value.slice(2), 16).toString(16) === value.slice(2).toLowerCase() - ) - || tg('validation.hexFormat') - ), -); - export default () => { const { balance, updateBalances } = useBalances(); const { currencyRates } = useCurrencies({ pollingDisabled: true }); diff --git a/src/protocols/ethereum/config.ts b/src/protocols/ethereum/config.ts index 8d6e7a933..8bcb0e330 100644 --- a/src/protocols/ethereum/config.ts +++ b/src/protocols/ethereum/config.ts @@ -14,6 +14,7 @@ export const ETH_COIN_PRECISION = 18; // Amount of decimals export const ETH_COINGECKO_COIN_ID = 'ethereum'; export const ETH_GAS_LIMIT = 21000; +export const ETH_CHAIN_NAMESPACE = 'eip155'; /** * Estimated time we need to wait for the middleware (etherscan) to sync it's state @@ -70,11 +71,11 @@ export const ETH_SAFE_CONFIRMATION_COUNT = 12; export const ETH_NETWORK_DEFAULT_SETTINGS: IDefaultNetworkTypeData = { [NETWORK_TYPE_MAINNET]: { nodeUrl: 'https://ethereum-rpc.publicnode.com', // TODO replace temp values - use our own node - chainId: '0x1', + chainId: '1', }, [NETWORK_TYPE_TESTNET]: { nodeUrl: 'https://ethereum-sepolia-rpc.publicnode.com', // TODO replace temp values - use our own node - chainId: '0xaa36a7', + chainId: '11155111', }, }; diff --git a/src/protocols/ethereum/libs/EthereumAdapter.ts b/src/protocols/ethereum/libs/EthereumAdapter.ts index a9e5a57fc..0ee26d6f2 100644 --- a/src/protocols/ethereum/libs/EthereumAdapter.ts +++ b/src/protocols/ethereum/libs/EthereumAdapter.ts @@ -41,7 +41,7 @@ import type { NetworkTypeDefault, } from '@/types'; import { PROTOCOLS } from '@/constants'; -import { getLastNotEmptyAccountIndex } from '@/utils'; +import { getLastNotEmptyAccountIndex, toHex } from '@/utils'; import Logger from '@/lib/logger'; import { BaseProtocolAdapter } from '@/protocols/BaseProtocolAdapter'; import { tg } from '@/popup/plugins/i18n'; @@ -100,7 +100,7 @@ export class EthereumAdapter extends BaseProtocolAdapter { defaultValue: ETH_NETWORK_DEFAULT_ENV_SETTINGS.chainId, validationRules: { url: false, - is_hex_format: true, + numeric: true, }, getPlaceholder: () => tg('pages.network.chainIdPlaceholder'), getLabel: () => tg('pages.network.chainIdLabel'), @@ -296,7 +296,7 @@ export class EthereumAdapter extends BaseProtocolAdapter { // All values are in wei const txData: FeeMarketEIP1559TxData = { - chainId, + chainId: toHex(chainId), nonce, to: contractId, data: contract.methods.transfer(recipient, hexAmount).encodeABI(), @@ -435,7 +435,7 @@ export class EthereumAdapter extends BaseProtocolAdapter { // All values are in wei const txData: FeeMarketEIP1559TxData = { - chainId, + chainId: toHex(chainId), nonce, to: recipient, value: hexAmount, diff --git a/src/protocols/ethereum/types.ts b/src/protocols/ethereum/types.ts index 266576c9c..705d0e28c 100644 --- a/src/protocols/ethereum/types.ts +++ b/src/protocols/ethereum/types.ts @@ -3,7 +3,8 @@ import { INetworkProtocolSettings } from '@/types'; /** * Settings specific to this protocol. */ -export type EthNetworkProtocolSettings = 'chainId'; +export type EthNetworkProtocolSettings = + | 'chainId'; // ref: https://docs.simplehash.com/reference/supported-chains-testnets /** * Settings that are not editable by the user but are assigned to specific network types. diff --git a/src/utils/common.ts b/src/utils/common.ts index f7c1253a8..39ab1023d 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -392,6 +392,10 @@ export function splitAddress(address: string | null): string { : ''; } +export function toHex(value: string) { + return `0x${parseInt(value, 10).toString(16)}`; +} + export function toShiftedBigNumber(value: number | string, precision: number): BigNumberPublic { return new BigNumber(value).shiftedBy(precision); }