Skip to content

Commit

Permalink
feat: adds wallet balance to org response
Browse files Browse the repository at this point in the history
  • Loading branch information
ec2sw committed Jul 20, 2022
1 parent e9d1434 commit 37db166
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/datalayer/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ const walletIsAvailable = async () => {
}
};

const getWalletBalance = async () => {
try {
if (getConfig().APP.USE_SIMULATOR) {
return Promise.resolve('999.00');
}

const options = {
url: `${rpcUrl}/get_wallet_balance`,
body: JSON.stringify({
wallet_id: 1,
}),
};

const response = await request(
Object.assign({}, getBaseOptions(), options),
);

if (response) {
const data = JSON.parse(response);
const balance = data?.wallet_balance?.spendable_balance;
return balance / 1000000000000;
}

return false;
} catch {
return false;
}
};

const hasUnconfirmedTransactions = async () => {
const options = {
url: `${rpcUrl}/get_transactions`,
Expand Down Expand Up @@ -107,4 +136,5 @@ export default {
walletIsSynced,
walletIsAvailable,
getPublicAddress,
getWalletBalance,
};
2 changes: 2 additions & 0 deletions src/models/organizations/organizations.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class Organization extends Model {
if (organizations[i].dataValues.isHome) {
organizations[i].dataValues.xchAddress =
await datalayer.getPublicAddress();
organizations[i].dataValues.balance =
await datalayer.getWalletBalance();
break;
}
}
Expand Down

0 comments on commit 37db166

Please sign in to comment.