Skip to content

Commit

Permalink
create campaign issues (#313)
Browse files Browse the repository at this point in the history
## PR Description:

Hello team,

This PR addresses an issue related to the retrieval of TRX token
balances within the Tron network. Users have reported inconsistencies
and inaccuracies in fetching their TRX token balances.

To resolve this issue, we have implemented a correction in our balance
retrieval process. This ensures accurate and reliable TRX token balance
information for our users within the Tron network.

## Changes Made:

- Corrected the TRX token balance retrieval mechanism to ensure accurate
results.


## Notes for Reviewers:

Please review the changes made in this PR to verify that the TRX token
balance retrieval issue has been effectively resolved. Test the balance
retrieval process for TRX tokens in the Tron network to confirm accurate
and consistent results.

Your attention and contributions are highly appreciated. Feel free to
provide any feedback or suggestions you may have.

Best regards,
Louay HICHRI
  • Loading branch information
hichri-louay committed Aug 17, 2023
2 parents 1162e9f + ebbb1e0 commit c82f477
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
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

0 comments on commit c82f477

Please sign in to comment.