From 264a56c79ae8f336e3598db0d8632cac4f5c3c46 Mon Sep 17 00:00:00 2001 From: Rahul Sethuram Date: Thu, 27 Aug 2020 15:33:49 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Expose=20node=20free=20balance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helpers/ethereum.ts | 14 ++++++++------ src/helpers/types.ts | 1 + src/schemas.ts | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/helpers/ethereum.ts b/src/helpers/ethereum.ts index 7ffb61e..154fd57 100644 --- a/src/helpers/ethereum.ts +++ b/src/helpers/ethereum.ts @@ -25,13 +25,11 @@ export function getIndexFromPath(path: string): number { return Number(path.replace(ETH_STANDARD_PATH, "").replace("/", "")); } -export async function getFreeBalanceOffChain( +export function getFreeBalanceOffChain( client: IConnextClient, assetId: string, -): Promise { - return (await client.getFreeBalance(assetId !== constants.AddressZero ? assetId : undefined))[ - client.signerAddress - ].toString(); +): Promise<{ [address: string]: BigNumber }> { + return client.getFreeBalance(assetId !== constants.AddressZero ? assetId : undefined); } export function getFreeBalanceOnChain( @@ -54,7 +52,11 @@ export async function getClientBalance( client.ethProvider, assetId, ); - return { freeBalanceOffChain, freeBalanceOnChain }; + return { + freeBalanceOffChain: freeBalanceOffChain[client.signerAddress].toString(), + nodeFreeBalanceOffChain: freeBalanceOffChain[client.nodeSignerAddress].toString(), + freeBalanceOnChain, + }; } export async function getEthBalance( diff --git a/src/helpers/types.ts b/src/helpers/types.ts index 6c3b77c..cd52fe4 100644 --- a/src/helpers/types.ts +++ b/src/helpers/types.ts @@ -105,6 +105,7 @@ export namespace RouteMethods { }; export type GetBalanceResponse = { freeBalanceOffChain?: string; + nodeFreeBalanceOffChain?: string; freeBalanceOnChain: string; }; diff --git a/src/schemas.ts b/src/schemas.ts index 8e5a6cd..f0cd7d4 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -56,6 +56,7 @@ export const BalanceResponseSchema = { properties: { freeBalanceOffChain: { type: "string", nullable: true }, freeBalanceOnChain: { type: "string" }, + nodeFreeBalanceOffChain: { type: "string", nullable: true }, }, };