Skip to content
This repository was archived by the owner on Feb 25, 2023. It is now read-only.
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
12 changes: 6 additions & 6 deletions src/routes/eth.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ router.post('/balances', async (req, res) => {
}
let tokenAddressList
if (paramData.tokenAddressList) {
tokenAddressList = paramData.tokenAddressList.split(separator)
tokenAddressList = JSON.parse(paramData.tokenAddressList)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will change the tokenAddressList from comma separated value to JSON string. HB client update will be needed for this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that is already handled in the PR 2690 mentioned above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes it harder to test with Postman, since the tokenAddressList param in eth/balances and eth/allowances endpoints is a more complex object. Instead of passing in a dict, can we pass in two arrays: tokenAddressList and tokenDecimalList?

}
debug(tokenAddressList)

const balances = {}
balances.ETH = await eth.getETHBalance(wallet, privateKey)
try {
Promise.all(
tokenAddressList.map(async (key) =>
balances[key] = await eth.getERC20Balance(wallet, key)
Object.keys(tokenAddressList).map(async (key, index) =>
balances[key] = await eth.getERC20Balance(wallet, key, tokenAddressList[key])
)).then(() => {
res.status(200).json({
network: eth.network,
Expand Down Expand Up @@ -94,14 +94,14 @@ router.post('/allowances', async (req, res) => {
}
let tokenAddressList
if (paramData.tokenAddressList) {
tokenAddressList = paramData.tokenAddressList.split(separator)
tokenAddressList = JSON.parse(paramData.tokenAddressList)
}

const approvals = {}
try {
Promise.all(
tokenAddressList.map(async (key) =>
approvals[key] = await eth.getERC20Allowance(wallet, spender, key)
Object.keys(tokenAddressList).map(async (key, index) =>
approvals[key] = await eth.getERC20Allowance(wallet, spender, key, tokenAddressList[key])
)).then(() => {
res.status(200).json({
network: eth.network,
Expand Down
8 changes: 4 additions & 4 deletions src/services/eth.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export default class Ethereum {
}

// get ERC-20 token balance
async getERC20Balance (wallet, tokenAddress) {
async getERC20Balance (wallet, tokenAddress, decimals) {
// instantiate a contract and pass in provider for read-only access
const contract = new ethers.Contract(tokenAddress, abi.ERC20Abi, this.provider)
try {
const balance = await contract.balanceOf(wallet.address)
return balance / 1e18.toString()
return balance / Math.pow(10, decimals).toString()
} catch (err) {
let reason
err.reason ? reason = err.reason : reason = 'error balance lookup'
Expand All @@ -51,12 +51,12 @@ export default class Ethereum {
}

// get ERC-20 token allowance
async getERC20Allowance (wallet, spender, tokenAddress) {
async getERC20Allowance (wallet, spender, tokenAddress, decimals) {
// instantiate a contract and pass in provider for read-only access
const contract = new ethers.Contract(tokenAddress, abi.ERC20Abi, this.provider)
try {
const allowance = await contract.allowance(wallet.address, spender)
return allowance / 1e18.toString()
return allowance / Math.pow(10, decimals).toString()
} catch (err) {
let reason
err.reason ? reason = err.reason : reason = 'error allowance lookup'
Expand Down