Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Enkrypt is a web3 wallet built from the ground up to support the multi-chain fut
- Shiden
- Shiden EVM
- Sepolia
- Syscoin
- Syscoin NEVM
- Telos EVM
- Unique
- Vara Network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const NetworkEndpoints: Record<string, string> = {
[NetworkNames.FormTestnet]: 'https://testnet-explorer.form.network/',
[NetworkNames.ArtheraTest]: 'https://explorer-test.arthera.net/',
[NetworkNames.Arthera]: 'https://explorer.arthera.net/',
[NetworkNames.SyscoinTest]: 'https://tanenbaum.io/',
[NetworkNames.Syscoin]: 'https://explorer.syscoin.org/',
[NetworkNames.SyscoinNEVMTest]: 'https://explorer.tanenbaum.io/',
[NetworkNames.SyscoinNEVM]: 'https://explorer.syscoin.org/',
[NetworkNames.RolluxTest]: 'https://rollux.tanenbaum.io/',
[NetworkNames.Rollux]: 'https://explorer.rollux.com/',
[NetworkNames.Blast]: 'https://api.blastscan.io/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { EvmNetwork } from '../../types/evm-network';
import { getKnownNetworkTokens } from './token-lists';
import { CoingeckoPlatform, NetworkNames } from '@enkryptcom/types';
import { NATIVE_TOKEN_ADDRESS } from '../common';
import getBlockscoutBalances from "./blockscout";
import getTomoBalances from './tomochain';
import getSolBalances from './solanachain';
import { CoinGeckoTokenMarket } from '@/libs/market-data/types';
Expand Down Expand Up @@ -120,9 +121,13 @@ const supportedNetworks: Record<SupportedNetworkNames, SupportedNetwork> = {
tbName: 'shib',
cgPlatform: CoingeckoPlatform.Shibarium,
},
[NetworkNames.SyscoinNEVM]: {
cgPlatform: CoingeckoPlatform.Syscoin,
bsEndpoint: true,
},
[NetworkNames.Rollux]: {
tbName: 'rollux',
cgPlatform: CoingeckoPlatform.Rollux,
bsEndpoint: true,
},
[NetworkNames.Telos]: {
tbName: 'tlos',
Expand Down Expand Up @@ -191,6 +196,8 @@ const getTokens = (
return getTomoBalances(chain, address);
} else if (chain === NetworkNames.Solana) {
return getSolBalances(network, address);
} else if (supportedNetworks[chain].bsEndpoint) {
return getBlockscoutBalances(chain, address);
}
let url = '';
if (chain === NetworkNames.Ethereum || chain === NetworkNames.Binance)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { SupportedNetworkNames, TokenBalance } from "./types/tokenbalance-mew";
import { NetworkEndpoints } from "@/providers/ethereum/libs/activity-handlers/providers/etherscan/configs";
import { NATIVE_TOKEN_ADDRESS } from "../common";
import { numberToHex } from "web3-utils";

interface TokenBalanceType {
token: string;
quantity: string;
error?: unknown;
}

interface TokenResponseItem {
token: {
address: string;
decimals: string;
name: string;
symbol: string;
};
value: string;
}

interface TokenResponse {
items: TokenResponseItem[];
}

const getBlockscoutBalances = (
chain: SupportedNetworkNames,
address: string
): Promise<TokenBalance[]> => {
const encodedAddress = encodeURIComponent(address);
const nativeTokenUrl = `${NetworkEndpoints[chain]}api/v2/addresses/${encodedAddress}`;
const tokenBalancesUrl = `${NetworkEndpoints[chain]}api/v2/addresses/${encodedAddress}/tokens?type=ERC-20`;

return Promise.all([
fetch(nativeTokenUrl).then((res) => res.json()),
fetch(tokenBalancesUrl).then((res) => res.json()),
])
.then(([nativeResponse, tokenResponse]: [any, TokenResponse]) => {
if (!nativeResponse?.coin_balance || !tokenResponse?.items) {
return Promise.reject("Error fetching balance data");
}

if (Number.isNaN(Number(nativeResponse.coin_balance))) {
return Promise.reject("Invalid native token balance");
}

// Map native token balance
const nativeBalance: TokenBalanceType = {
token: NATIVE_TOKEN_ADDRESS,
quantity: nativeResponse.coin_balance,
};

// Map token balances
const tokenBalances: TokenBalanceType[] = Array.isArray(
tokenResponse?.items
)
? tokenResponse.items
.filter(
(item) =>
item?.token?.address &&
typeof item.token.address === "string" &&
item.value !== undefined
)
.map((item) => ({
token: item.token.address.toLowerCase(),
quantity: item.value,
}))
: [];

// Merge native token and token balances
const allBalances = [nativeBalance, ...tokenBalances];

// Convert to TokenBalance format
return allBalances.map((tb) => ({
contract: tb.token,
balance: numberToHex(tb.quantity), // Convert to hex format
}));
Comment on lines +74 to +77
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for hex conversion.

The numberToHex conversion could fail with invalid inputs. Consider adding error handling:

  return allBalances.map((tb) => ({
    contract: tb.token,
-   balance: numberToHex(tb.quantity), // Convert to hex format
+   balance: (() => {
+     try {
+       return numberToHex(tb.quantity);
+     } catch (error) {
+       console.error(`Failed to convert balance to hex for token ${tb.token}:`, error);
+       return '0x0';
+     }
+   })(),
  }));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return allBalances.map((tb) => ({
contract: tb.token,
balance: numberToHex(tb.quantity), // Convert to hex format
}));
return allBalances.map((tb) => ({
contract: tb.token,
balance: (() => {
try {
return numberToHex(tb.quantity);
} catch (error) {
console.error(`Failed to convert balance to hex for token ${tb.token}:`, error);
return '0x0';
}
})(),
}));

})
.catch((error) => {
console.error("Error fetching balances:", error);
throw error;
});
};

export default getBlockscoutBalances;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { CoingeckoPlatform, NetworkNames } from '@enkryptcom/types';
import { CGToken, SupportedNetworkNames } from './types/tokenbalance-mew';
const TOKEN_FETCH_TTL = 1000 * 60 * 60;
const TokenList: Record<SupportedNetworkNames, string> = {
[NetworkNames.SyscoinNEVM]: `https://tokens.coingecko.com/${CoingeckoPlatform.Syscoin}/all.json`,
[NetworkNames.Rollux]: `https://tokens.coingecko.com/${CoingeckoPlatform.Rollux}/all.json`,
[NetworkNames.Binance]: `https://tokens.coingecko.com/${CoingeckoPlatform.Binance}/all.json`,
[NetworkNames.Ethereum]: `https://tokens.coingecko.com/${CoingeckoPlatform.Ethereum}/all.json`,
[NetworkNames.Matic]: `https://tokens.coingecko.com/${CoingeckoPlatform.Matic}/all.json`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ export interface TokenBalance {
balance: string;
}
export interface SupportedNetwork {
tbName: string;
tbName?: string;
cgPlatform?: string;
bsEndpoint?: boolean;
}
export interface CGToken {
chainId: `0x${string}`;
Expand Down Expand Up @@ -50,6 +51,7 @@ export type SupportedNetworkNames =
| NetworkNames.Celo
| NetworkNames.ZkSync
| NetworkNames.Telos
| NetworkNames.SyscoinNEVM
| NetworkNames.Rollux
| NetworkNames.Sanko
| NetworkNames.Degen
Expand Down
12 changes: 6 additions & 6 deletions packages/extension/src/providers/ethereum/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import shibNode from './shib';
import artheraNode from './aa';
import formTestnet from './form-testnet';
import artheraTestNode from './aat';
import syscoinTestNode from './tsys';
import syscoinNode from './sys';
import rolluxTestNode from './trlx';
import rolluxNode from './rlx';
import syscoinNEVMTestNode from './syscoin/nevm-testnet';
import syscoinNEVMNode from './syscoin/nevm';
import rolluxTestNode from './syscoin/rollux-testnet';
import rolluxNode from './syscoin/rollux';
import cagaAnkara from './cagaAnkara';
import telosNode from './tlos';
import blastNode from './blast';
Expand Down Expand Up @@ -108,8 +108,8 @@ export default {
arthera: artheraNode,
formTestnet: formTestnet,
artheraTest: artheraTestNode,
syscoinTest: syscoinTestNode,
syscoin: syscoinNode,
syscoinNEVMTest: syscoinNEVMTestNode,
syscoinNEVM: syscoinNEVMNode,
rolluxTest: rolluxTestNode,
rollux: rolluxNode,
cagaAnkara: cagaAnkara,
Expand Down
26 changes: 0 additions & 26 deletions packages/extension/src/providers/ethereum/networks/sys.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import icon from '../icons/tsys_nevm.svg';
import { 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 syscoinNEVMTestOptions: EvmNetworkOptions = {
name: NetworkNames.SyscoinNEVMTest,
name_long: 'Syscoin NEVM Testnet',
homePage: 'https://www.syscoin.org/',
blockExplorerTX: 'https://explorer.tanenbaum.io/tx/[[txHash]]',
blockExplorerAddr: 'https://explorer.tanenbaum.io/address/[[address]]',
chainID: '0x1644',
isTestNetwork: true,
currencyName: 'TSYS',
currencyNameLong: 'Test Syscoin',
node: 'wss://rpc.tanenbaum.io/wss',
icon,
buyLink: 'https://faucet.syscoin.org',
activityHandler: wrapActivityHandler(EtherscanActivity),
};

const syscoinNEVMTest = new EvmNetwork(syscoinNEVMTestOptions);

export default syscoinNEVMTest;
29 changes: 29 additions & 0 deletions packages/extension/src/providers/ethereum/networks/syscoin/nevm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import icon from '../icons/sys_nevm.svg';
import { CoingeckoPlatform, NetworkNames } from "@enkryptcom/types";
import { EvmNetwork, EvmNetworkOptions } from "../../types/evm-network";
import assetsInfoHandler from "@/providers/ethereum/libs/assets-handlers/assetinfo-mew";
import { EtherscanActivity } from "../../libs/activity-handlers";
import wrapActivityHandler from "@/libs/activity-state/wrap-activity-handler";

const syscoinNEVMOptions: EvmNetworkOptions = {
name: NetworkNames.SyscoinNEVM,
name_long: "Syscoin NEVM",
homePage: "https://www.syscoin.org/",
blockExplorerTX: "https://explorer.syscoin.org/tx/[[txHash]]",
blockExplorerAddr: "https://explorer.syscoin.org/address/[[address]]",
chainID: "0x39",
isTestNetwork: false,
currencyName: "SYS",
currencyNameLong: "Syscoin",
node: "wss://rpc.syscoin.org/wss",
coingeckoID: "syscoin",
coingeckoPlatform: CoingeckoPlatform.Syscoin,
icon,
assetsInfoHandler,
buyLink: 'https://trade.coinify.com/syscoin?defaultCryptoCurrency=SYSEVM&cryptoCurrencies=SYSROLLUX,SYSEVM,SYS&targetPage=buy',
activityHandler: wrapActivityHandler(EtherscanActivity),
};

const syscoinNEVM = new EvmNetwork(syscoinNEVMOptions);

export default syscoinNEVM;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import icon from './icons/tsys_rollux.svg';
import icon from '../icons/tsys_rollux.svg';
import { NetworkNames } from '@enkryptcom/types';
import { EvmNetwork, EvmNetworkOptions } from '../types/evm-network';
import { EtherscanActivity } from '../libs/activity-handlers';
import { EvmNetwork, EvmNetworkOptions } from '../../types/evm-network';
import { EtherscanActivity } from '../../libs/activity-handlers';
import wrapActivityHandler from '@/libs/activity-state/wrap-activity-handler';

const rolluxTestOptions: EvmNetworkOptions = {
Expand All @@ -16,6 +16,7 @@ const rolluxTestOptions: EvmNetworkOptions = {
currencyNameLong: 'Test Syscoin',
node: 'wss://rpc-tanenbaum.rollux.com/wss',
icon,
buyLink: 'https://faucet.rollux.com',
activityHandler: wrapActivityHandler(EtherscanActivity),
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import icon from './icons/sys_rollux.svg';
import icon from '../icons/sys_rollux.svg';
import { NetworkNames, CoingeckoPlatform } from '@enkryptcom/types';
import { EvmNetwork, EvmNetworkOptions } from '../types/evm-network';
import { EtherscanActivity } from '../libs/activity-handlers';
import { EvmNetwork, EvmNetworkOptions } from '../../types/evm-network';
import assetsInfoHandler from "@/providers/ethereum/libs/assets-handlers/assetinfo-mew";
import { EtherscanActivity } from '../../libs/activity-handlers';
import wrapActivityHandler from '@/libs/activity-state/wrap-activity-handler';
import assetsInfoHandler from '@/providers/ethereum/libs/assets-handlers/assetinfo-mew';

const rolluxOptions: EvmNetworkOptions = {
name: NetworkNames.Rollux,
Expand All @@ -20,6 +20,7 @@ const rolluxOptions: EvmNetworkOptions = {
coingeckoPlatform: CoingeckoPlatform.Rollux,
icon,
assetsInfoHandler,
buyLink: 'https://trade.coinify.com/syscoin?defaultCryptoCurrency=SYSROLLUX&cryptoCurrencies=SYSROLLUX,SYSEVM,SYS&targetPage=buy',
activityHandler: wrapActivityHandler(EtherscanActivity),
};

Expand Down
24 changes: 0 additions & 24 deletions packages/extension/src/providers/ethereum/networks/tsys.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface EvmNetworkOptions {
currencyNameLong: string;
node: string;
icon: string;
buyLink?: string | undefined;
coingeckoID?: string;
coingeckoPlatform?: CoingeckoPlatform;
basePath?: string;
Expand Down Expand Up @@ -98,6 +99,7 @@ export class EvmNetwork extends BaseNetwork {

baseOptions.customTokens = baseOptions.customTokens ?? true;
super(baseOptions);
this.options = options;

this.chainID = options.chainID;
this.assetsInfoHandler = options.assetsInfoHandler;
Expand Down
20 changes: 16 additions & 4 deletions packages/extension/src/ui/action/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,26 @@ const toggleDepositWindow = () => {
showDepositWindow.value = !showDepositWindow.value;
};
const openBuyPage = () => {
const buyLink =
currentNetwork.value.name === NetworkNames.KadenaTestnet
? (currentNetwork.value as KadenaNetwork).options.buyLink
: `https://ccswap.myetherwallet.com/?to=${currentNetwork.value.displayAddress(
const buyLink = (() => {
switch (currentNetwork.value.name) {
case NetworkNames.KadenaTestnet:
return (currentNetwork.value as KadenaNetwork).options.buyLink;
case NetworkNames.SyscoinNEVM:
case NetworkNames.Rollux:
return `${(currentNetwork.value as EvmNetwork).options.buyLink}&address=${currentNetwork.value.displayAddress(
accountHeaderData.value.selectedAccount!.address
)}`;
case NetworkNames.SyscoinNEVMTest:
case NetworkNames.RolluxTest:
return (currentNetwork.value as EvmNetwork).options.buyLink;
default:
return `https://ccswap.myetherwallet.com/?to=${currentNetwork.value.displayAddress(
accountHeaderData.value.selectedAccount!.address,
)}&network=${currentNetwork.value.name}&crypto=${
currentNetwork.value.currencyName
}&platform=enkrypt`;
}
})();
Browser.tabs.create({
url: buyLink,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export enum NetworkNames {
FormTestnet = "FormTestnet",
AssetHubDOT = "AssetHubDOT",
AssetHubKSM = "AssetHubKSM",
SyscoinTest = "TSYS",
Syscoin = "SYS",
SyscoinNEVMTest = "TSYS",
SyscoinNEVM = "SYS",
RolluxTest = "TRLX",
Rollux = "RLX",
CagaAnkara = "CagaAnkara",
Expand Down
Loading