Skip to content
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

add missing controllers for gas price arthera evm #420

Merged
merged 1 commit into from
Feb 14, 2024
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
69 changes: 36 additions & 33 deletions controllers/wallet.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,6 +28,7 @@ const {
bttConnexion,
tronConnexion,
webTronInstance,
artheraConnexion,
} = require('../blockchainConnexion')

const {
Expand Down Expand Up @@ -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()

Expand All @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1707,9 +1723,6 @@ exports.exportKeyStoreMobile = async (req, res) => {
}
}




exports.exportBtc = async (req, res) => {
try {
res.attachment()
Expand All @@ -1730,8 +1743,6 @@ exports.exportBtc = async (req, res) => {
} catch (err) {}
}



exports.exportEth = async (req, res) => {
try {
res.attachment()
Expand All @@ -1753,9 +1764,6 @@ exports.exportEth = async (req, res) => {
}
}




exports.exportTron = async (req, res) => {
try {
res.attachment()
Expand All @@ -1777,8 +1785,6 @@ exports.exportTron = async (req, res) => {
}
}



exports.exportTronV2 = async (req, res) => {
try {
res.attachment()
Expand All @@ -1800,8 +1806,6 @@ exports.exportTronV2 = async (req, res) => {
}
}



exports.exportBtcV2 = async (req, res) => {
try {
res.attachment()
Expand All @@ -1826,7 +1830,6 @@ exports.exportBtcV2 = async (req, res) => {
} catch (err) {}
}


exports.exportEthV2 = async (req, res) => {
try {
res.attachment()
Expand Down
6 changes: 0 additions & 6 deletions routes/wallet.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const {
migrationWalletValidation,
cryptoListValidation,
} = require('../middleware/walletValidator.middleware')
const { artheraConnexion } = require('../blockchainConnexion')

/**
* @swagger
Expand Down Expand Up @@ -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
Loading