Skip to content
This repository has been archived by the owner on May 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #90 from connext/89-expose-node-free-balance
Browse files Browse the repository at this point in the history
✨ Expose node free balance
  • Loading branch information
pedrouid authored Aug 28, 2020
2 parents 24f4101 + 264a56c commit 868ddcc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/helpers/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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(
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export namespace RouteMethods {
};
export type GetBalanceResponse = {
freeBalanceOffChain?: string;
nodeFreeBalanceOffChain?: string;
freeBalanceOnChain: string;
};

Expand Down
1 change: 1 addition & 0 deletions src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const BalanceResponseSchema = {
properties: {
freeBalanceOffChain: { type: "string", nullable: true },
freeBalanceOnChain: { type: "string" },
nodeFreeBalanceOffChain: { type: "string", nullable: true },
},
};

Expand Down

0 comments on commit 868ddcc

Please sign in to comment.