mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 13:47:12 +00:00
Fix getAccount
This commit is contained in:
parent
69d9ef5ce8
commit
344d980b5f
@ -95,9 +95,9 @@ describe("CosmosConnection", () => {
|
||||
const connection = await CosmosConnection.establish(httpUrl, defaultPrefix, defaultTokens);
|
||||
const token = await connection.getToken("COSM" as TokenTicker);
|
||||
expect(token).toEqual({
|
||||
fractionalDigits: 6,
|
||||
tokenName: "Fee Token",
|
||||
tokenTicker: "COSM" as TokenTicker,
|
||||
fractionalDigits: 6,
|
||||
tokenName: "Fee Token",
|
||||
tokenTicker: "COSM" as TokenTicker,
|
||||
});
|
||||
connection.disconnect();
|
||||
});
|
||||
@ -150,9 +150,10 @@ describe("CosmosConnection", () => {
|
||||
throw new Error("Expected account not to be undefined");
|
||||
}
|
||||
expect(account.address).toEqual(defaultAddress);
|
||||
expect(account.pubkey).toEqual(defaultPubkey);
|
||||
// Unsupported coins are filtered out
|
||||
expect(account.balance.length).toEqual(1);
|
||||
// Undefined until we sign a transaction
|
||||
expect(account.pubkey).toEqual(undefined);
|
||||
// Starts with two tokens
|
||||
expect(account.balance.length).toEqual(2);
|
||||
connection.disconnect();
|
||||
});
|
||||
|
||||
@ -164,12 +165,10 @@ describe("CosmosConnection", () => {
|
||||
throw new Error("Expected account not to be undefined");
|
||||
}
|
||||
expect(account.address).toEqual(defaultAddress);
|
||||
expect(account.pubkey).toEqual({
|
||||
algo: Algorithm.Secp256k1,
|
||||
data: fromBase64("A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ"),
|
||||
});
|
||||
// Unsupported coins are filtered out
|
||||
expect(account.balance.length).toEqual(1);
|
||||
// Undefined until we sign a transaction
|
||||
expect(account.pubkey).toEqual(undefined);
|
||||
// Starts with two tokens
|
||||
expect(account.balance.length).toEqual(2);
|
||||
connection.disconnect();
|
||||
});
|
||||
});
|
||||
|
@ -145,19 +145,23 @@ export class CosmosConnection implements BlockchainConnection {
|
||||
const address = isPubkeyQuery(query) ? pubkeyToAddress(query.pubkey, this.prefix) : query.address;
|
||||
const { result } = await this.restClient.authAccounts(address);
|
||||
const account = result.value;
|
||||
if (!account.address) {
|
||||
return undefined;
|
||||
}
|
||||
const supportedCoins = account.coins.filter(({ denom }) =>
|
||||
this.tokenInfo.find(token => token.denom === denom),
|
||||
);
|
||||
return account.public_key === null
|
||||
const pubkey = !account.public_key
|
||||
? undefined
|
||||
: {
|
||||
address: address,
|
||||
balance: supportedCoins.map(decodeAmount(this.tokenInfo)),
|
||||
pubkey: {
|
||||
algo: Algorithm.Secp256k1,
|
||||
data: fromBase64(account.public_key.value) as PubkeyBytes,
|
||||
},
|
||||
algo: Algorithm.Secp256k1,
|
||||
data: fromBase64(account.public_key.value) as PubkeyBytes,
|
||||
};
|
||||
return {
|
||||
address: address,
|
||||
balance: supportedCoins.map(decodeAmount(this.tokenInfo)),
|
||||
pubkey: pubkey,
|
||||
};
|
||||
}
|
||||
|
||||
public watchAccount(_account: AccountQuery): Stream<Account | undefined> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user