-
Notifications
You must be signed in to change notification settings - Fork 237
Update Syscoin and Rollux integration #601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kvhnuke
merged 5 commits into
enkryptcom:devop/new-networks-2
from
fernando-syslabs:main
Jan 23, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f370ca3
Update Syscoin and Rollux integration.
DevElCuy 0b8b607
Remove duplicates and improve error handling of blockscout client.
DevElCuy 6c6360e
Refactor blockscout client's address handler.
DevElCuy de523f0
Add links to faucet and on-ramp.
DevElCuy ffdf960
Remove debug console.log statement.
DevElCuy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/extension/src/providers/ethereum/libs/assets-handlers/blockscout.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| })); | ||
| }) | ||
| .catch((error) => { | ||
| console.error("Error fetching balances:", error); | ||
| throw error; | ||
| }); | ||
| }; | ||
|
|
||
| export default getBlockscoutBalances; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
packages/extension/src/providers/ethereum/networks/syscoin/nevm-testnet.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
29
packages/extension/src/providers/ethereum/networks/syscoin/nevm.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
packages/extension/src/providers/ethereum/networks/tsys.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
numberToHexconversion 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