From 79702340045fd4776d89e1e6cbae9bee6f185084 Mon Sep 17 00:00:00 2001 From: hichri-louay Date: Wed, 14 Feb 2024 16:15:01 +0100 Subject: [PATCH] add missing controllers for gas price arthera evm --- controllers/wallet.controller.js | 69 +++++++++++++++++--------------- routes/wallet.routes.js | 6 --- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/controllers/wallet.controller.js b/controllers/wallet.controller.js index b4f91a7a..2f5345e1 100644 --- a/controllers/wallet.controller.js +++ b/controllers/wallet.controller.js @@ -9,9 +9,7 @@ var fs = require('fs') var bip39 = require('bip39') var bip32 = require('bip32') var bip38 = require('bip38') -const { ethers } = require('ethers'); - - +const { ethers } = require('ethers') const Web3 = require('web3') const { @@ -30,6 +28,7 @@ const { bttConnexion, tronConnexion, webTronInstance, + artheraConnexion, } = require('../blockchainConnexion') const { @@ -272,6 +271,15 @@ exports.gasPriceBtt = async (req, res) => { }) } +exports.gasPriceAA = async (req, res) => { + let Web3ETH = await artheraConnexion() + + var gasPrice = await Web3ETH.eth.getGasPrice() + return responseHandler.makeResponseData(res, 200, 'success', { + gasPrice: (gasPrice * 280) / 1000000000, + }) +} + exports.gasPriceTrx = async (req, res) => { let tronWeb = await webTronInstance() @@ -291,7 +299,6 @@ exports.getCharts = async (req, res) => { return responseHandler.makeResponseData(res, 200, 'success', charts) } - exports.cryptoPriceDetails = async (req, res) => { let chart = await getChartVariation(req.query.cryptolist) @@ -534,51 +541,60 @@ exports.transferTokensController = async (req, res) => { } } - exports.getBalanceExternalWallet = async (req, res) => { try { - const { token, walletAddress } = req.body; + const { token, walletAddress } = req.body const networks = [ - { name: 'ethereum', providerUrl: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY' }, + { + name: 'ethereum', + providerUrl: 'https://mainnet.infura.io/v3/YOUR_INFURA_API_KEY', + }, { name: 'bsc', providerUrl: 'https://bsc-dataseed.binance.org/' }, { name: 'polygon', providerUrl: 'https://polygon-rpc.com/' }, // Add more networks here if needed - ]; + ] - let balanceResponse; + let balanceResponse for (const networkObj of networks) { try { - const provider = new ethers.providers.JsonRpcProvider(networkObj.providerUrl); + const provider = new ethers.providers.JsonRpcProvider( + networkObj.providerUrl + ) const contract = new ethers.Contract( token, ['function balanceOf(address) view returns (uint256)'], provider - ); + ) - const balance = await contract.balanceOf(walletAddress); - const formattedBalance = ethers.utils.formatUnits(balance, 18); // Assuming 18 decimals, adjust as needed + const balance = await contract.balanceOf(walletAddress) + const formattedBalance = ethers.utils.formatUnits(balance, 18) // Assuming 18 decimals, adjust as needed - balanceResponse = { balance: formattedBalance, network: networkObj.name }; - res.json(balanceResponse); - return; // Return immediately upon successful balance fetch + balanceResponse = { + balance: formattedBalance, + network: networkObj.name, + } + res.json(balanceResponse) + return // Return immediately upon successful balance fetch } catch (error) { // Handle network-specific errors here - console.error(`Error fetching balance for ${networkObj.name}: ${error.message}`); + console.error( + `Error fetching balance for ${networkObj.name}: ${error.message}` + ) } } // If the loop completes without returning, it means all networks failed res.status(500).json({ error: 'An error occurred while fetching the balance for all networks.', - }); + }) } catch (err) { res.status(500).json({ error: 'An error occurred while setting up network connections.', - }); + }) } -}; +} exports.addNewToken = async (req, res) => { try { @@ -1707,9 +1723,6 @@ exports.exportKeyStoreMobile = async (req, res) => { } } - - - exports.exportBtc = async (req, res) => { try { res.attachment() @@ -1730,8 +1743,6 @@ exports.exportBtc = async (req, res) => { } catch (err) {} } - - exports.exportEth = async (req, res) => { try { res.attachment() @@ -1753,9 +1764,6 @@ exports.exportEth = async (req, res) => { } } - - - exports.exportTron = async (req, res) => { try { res.attachment() @@ -1777,8 +1785,6 @@ exports.exportTron = async (req, res) => { } } - - exports.exportTronV2 = async (req, res) => { try { res.attachment() @@ -1800,8 +1806,6 @@ exports.exportTronV2 = async (req, res) => { } } - - exports.exportBtcV2 = async (req, res) => { try { res.attachment() @@ -1826,7 +1830,6 @@ exports.exportBtcV2 = async (req, res) => { } catch (err) {} } - exports.exportEthV2 = async (req, res) => { try { res.attachment() diff --git a/routes/wallet.routes.js b/routes/wallet.routes.js index 6ae62c1e..6e0a8d34 100644 --- a/routes/wallet.routes.js +++ b/routes/wallet.routes.js @@ -65,7 +65,6 @@ const { migrationWalletValidation, cryptoListValidation, } = require('../middleware/walletValidator.middleware') -const { artheraConnexion } = require('../blockchainConnexion') /** * @swagger @@ -939,9 +938,4 @@ router.get('/nfts/:address', checkEVMValidation, getNftByAddress) router.post('/getBalance', verifyAuth, getBalanceByToken) -router.get('/arthera', async (req, res) => { - const result = await artheraConnexion() - console.log({ result }) -}) - module.exports = router