Simplify decodeAmount
This commit is contained in:
parent
4377fdd8ab
commit
c81c356fe3
@ -160,7 +160,7 @@ export class CosmWasmConnection implements BlockchainConnection {
|
||||
};
|
||||
return {
|
||||
address: address,
|
||||
balance: supportedCoins.map(decodeAmount(this.tokenInfo)),
|
||||
balance: supportedCoins.map(coin => decodeAmount(this.tokenInfo, coin)),
|
||||
pubkey: pubkey,
|
||||
};
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ describe("decode", () => {
|
||||
denom: "uatom",
|
||||
amount: "11657995",
|
||||
};
|
||||
expect(decodeAmount(defaultTokens)(amount)).toEqual(defaultAmount);
|
||||
expect(decodeAmount(defaultTokens, amount)).toEqual(defaultAmount);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -42,10 +42,9 @@ export function decodeFullSignature(signature: amino.StdSignature, nonce: number
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: return null vs throw exception for undefined???
|
||||
export const decodeAmount = (tokens: TokenInfos) => (coin: amino.Coin): Amount => {
|
||||
export function decodeAmount(tokens: TokenInfos, coin: amino.Coin): Amount {
|
||||
return coinToAmount(tokens, coin);
|
||||
};
|
||||
}
|
||||
|
||||
export function parseMsg(msg: amino.Msg, chainId: ChainId, tokens: TokenInfos): SendTransaction {
|
||||
if (msg.type !== "cosmos-sdk/MsgSend") {
|
||||
@ -63,7 +62,7 @@ export function parseMsg(msg: amino.Msg, chainId: ChainId, tokens: TokenInfos):
|
||||
chainId: chainId,
|
||||
sender: msgValue.from_address as Address,
|
||||
recipient: msgValue.to_address as Address,
|
||||
amount: decodeAmount(tokens)(msgValue.amount[0]),
|
||||
amount: decodeAmount(tokens, msgValue.amount[0]),
|
||||
};
|
||||
}
|
||||
|
||||
@ -72,7 +71,7 @@ export function parseFee(fee: amino.StdFee, tokens: TokenInfos): Fee {
|
||||
throw new Error("Only fee with one amount is supported");
|
||||
}
|
||||
return {
|
||||
tokens: decodeAmount(tokens)(fee.amount[0]),
|
||||
tokens: decodeAmount(tokens, fee.amount[0]),
|
||||
gasLimit: fee.gas,
|
||||
};
|
||||
}
|
||||
|
||||
@ -16,7 +16,6 @@ export function amountToCoin(lookup: ReadonlyArray<TokenInfo>, amount: Amount):
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: return null vs throw exception for undefined???
|
||||
export function coinToAmount(tokens: TokenInfos, coin: amino.Coin): Amount {
|
||||
const match = tokens.find(({ denom }) => denom === coin.denom);
|
||||
if (!match) {
|
||||
|
||||
2
packages/bcp/types/decode.d.ts
vendored
2
packages/bcp/types/decode.d.ts
vendored
@ -17,7 +17,7 @@ import { TokenInfos } from "./types";
|
||||
export declare function decodePubkey(pubkey: amino.PubKey): PubkeyBundle;
|
||||
export declare function decodeSignature(signature: string): SignatureBytes;
|
||||
export declare function decodeFullSignature(signature: amino.StdSignature, nonce: number): FullSignature;
|
||||
export declare const decodeAmount: (tokens: TokenInfos) => (coin: amino.Coin) => Amount;
|
||||
export declare function decodeAmount(tokens: TokenInfos, coin: amino.Coin): Amount;
|
||||
export declare function parseMsg(msg: amino.Msg, chainId: ChainId, tokens: TokenInfos): SendTransaction;
|
||||
export declare function parseFee(fee: amino.StdFee, tokens: TokenInfos): Fee;
|
||||
export declare function parseTx(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user