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

create campaign issues #313

Merged
merged 1 commit into from
Aug 17, 2023
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
6 changes: 3 additions & 3 deletions controllers/wallet.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ exports.getBalanceByToken = async (req, res) => {
const balanceFormatted = formatTokenBalance(balance, decimals);
return responseHandler.makeResponseData(res, 200, 'success', balanceFormatted);
} else {
const balance = await getNativeBalance(web3Instance, walletAddress);
const balance = await getNativeBalance(web3Instance, walletAddress, network);
return responseHandler.makeResponseData(res, 200, 'success', balance);
}
} catch (err) {
Expand Down Expand Up @@ -521,9 +521,9 @@ exports.checkWalletToken = async (req, res) => {
const tronWeb = await webTronInstance()

const networks = [
{ name: 'bep20', web3: Web3BEP20.eth, abi: Constants.bep20.abi },
{ name: 'bep20', web3: Web3BEP20.eth, abi: Constants.token.abi },
{ name: 'erc20', web3: Web3ETH.eth, abi: Constants.token.abi },
{ name: 'polygon', web3: web3MATIC.eth, abi: Constants.bep20.abi },
{ name: 'polygon', web3: web3MATIC.eth, abi: Constants.token.abi },
{ name: 'bttc', web3: web3BTT.eth, abi: Constants.token.abi },

// Add more EVM networks here if needed
Expand Down
2 changes: 1 addition & 1 deletion middleware/walletValidator.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const validatePassword = () => Joi.string().min(8).required().custom((value) =>


// VALIDATION NETWORK
const validateNetworks = (validNetworks) => Joi.string().required().custom((value) => {
const validateNetworks = (validNetworks) => Joi.string().allow(null).required().custom((value) => {
for(let i = 0; i < validNetworks.length ; i++) {
if(validNetworks[i] === value.toString().toLowerCase()) {
return value;
Expand Down
21 changes: 17 additions & 4 deletions web3/wallets.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,15 +910,28 @@ exports.formatTokenBalance = (balance, decimals) => {
};

// Helper function to get native balance (ETH, TRX, etc.) and format it
exports.getNativeBalance = async (web3Instance, walletAddress) => {
const balanceWei = await web3Instance.eth.getBalance(walletAddress);
const balanceFormatted = web3Instance.utils.fromWei(balanceWei, 'ether');
return balanceFormatted;
exports.getNativeBalance = async (web3Instance, walletAddress, network) => {
if(network === 'tron') {
const account = await web3Instance.trx.getAccount(walletAddress);
if (account && account.balance) {
const balanceFormatted = web3Instance.fromSun(account.balance);
return balanceFormatted;
}
return '0';
} else {
const balanceWei = await web3Instance.eth.getBalance(walletAddress);
const balanceFormatted = web3Instance.utils.fromWei(balanceWei, 'ether');
return balanceFormatted;
}



};

exports.getTronBalance = async (webTron, token, address, isTrx = false) => {
try {
if (isTrx) {
console.log({trx: webTron.trx})
let amount = await webTron.trx.getBalance(address)
return amount.toString()
}
Expand Down