Skip to content

Commit

Permalink
Bump to 9.0.1, fix loadMetaData for non-vesting accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Constantine Moore committed Jan 26, 2022
1 parent d6b20ce commit f6bea97
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kava-labs/javascript-sdk",
"version": "9.0.0",
"version": "9.0.1",
"description": "Supports interaction with the Kava blockchain via a REST api",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
10 changes: 5 additions & 5 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const api = {
getCommittees: '/committee/committees',
getProposal: '/committee/proposals', // endpoint also used by getProposer, getProposalTally, getProposalVotes
getDistributionRewards: '/distribution/delegators',
getDelegations: '/staking/delegators',
getDelegations: '/staking/delegators',
};

/**
Expand Down Expand Up @@ -316,10 +316,10 @@ export class KavaClient {
const path = api.getBalances + '/' + address;
const res = await tx.getTx(path, this.baseURI, timeout);
if (res && res.data) {
return res.data.result;
return res.data.result as Coin[];
}
}

/**
* Get an account's delegators reward
* @param {String} address account to query
Expand All @@ -346,7 +346,7 @@ export class KavaClient {
if (res && res.data) {
return res.data.result;
}
}
}

/**
* Get the total supply of coins on the chain
Expand Down Expand Up @@ -1084,7 +1084,7 @@ export class KavaClient {
}

/***************************************************
* Committee
* Committee
***************************************************/
/**
* Get the params of the committee module
Expand Down
15 changes: 13 additions & 2 deletions src/tx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,19 @@ const retry: RetryFunction = async (
async function loadMetaData(address: string, base: string, timeout = 2000) {
const path = api.getAccount + '/' + address;
const res = await getTx(path, base, timeout);
const accNum = res?.data?.result?.value?.base_vesting_account?.base_account?.account_number;
const seqNum = res?.data?.result?.value?.base_vesting_account?.base_account?.sequence || "0";
let accNum: string;
let seqNum: string;
if (res?.data?.result?.type === 'cosmos-sdk/BaseAccount') {
accNum = res?.data?.result?.value?.account_number;
seqNum = res?.data?.result?.value?.sequence || '0';
} else {
accNum =
res?.data?.result?.value?.base_vesting_account?.base_account
?.account_number;
seqNum =
res?.data?.result?.value?.base_vesting_account?.base_account?.sequence ||
'0';
}
if (!(accNum || seqNum)) {
throw new Error(
'account number or sequence number from rest server are undefined'
Expand Down

0 comments on commit f6bea97

Please sign in to comment.