-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix GovAPI endpoints (deposits, votes) and handle LCD API return null…
… in a Coins.Data value. (#112) * Fix TypeError when LCD API return null in a Coins.Data value * Fix GovAPI votes endpoint and add type to deposits endpoint Co-authored-by: Paul Kim <[email protected]> Co-authored-by: Yun Yeo <[email protected]> Co-authored-by: brycepratt <[email protected]> Co-authored-by: Jon Lund Steffensen <[email protected]>
- Loading branch information
1 parent
b17807d
commit 7bb9179
Showing
5 changed files
with
116 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Coins } from './Coins'; | ||
import { JSONSerializable } from '../util/json'; | ||
import { AccAddress } from './bech32'; | ||
|
||
/** | ||
* Stores deposit information for a proposal | ||
*/ | ||
export class Deposit extends JSONSerializable<Deposit.Data> { | ||
public amount: Coins; | ||
/** | ||
* @param proposal_id Id of porposal to deposit to | ||
* @param depositor depositor's account address | ||
* @param amount amount to deposit | ||
*/ | ||
constructor( | ||
public proposal_id: number, | ||
public depositor: AccAddress, | ||
amount: Coins.Input | ||
) { | ||
super(); | ||
this.amount = new Coins(amount); | ||
} | ||
|
||
public static fromData(data: Deposit.Data): Deposit { | ||
const { proposal_id, depositor, amount } = data; | ||
return new Deposit( | ||
Number.parseInt(proposal_id), | ||
depositor, | ||
Coins.fromData(amount) | ||
); | ||
} | ||
|
||
public toData(): Deposit.Data { | ||
const { proposal_id, depositor, amount } = this; | ||
return { | ||
proposal_id: proposal_id.toString(), | ||
depositor, | ||
amount: amount.toData(), | ||
}; | ||
} | ||
} | ||
|
||
export namespace Deposit { | ||
export interface Data { | ||
proposal_id: string; | ||
depositor: AccAddress; | ||
amount: Coins.Data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { JSONSerializable } from '../util/json'; | ||
import { AccAddress } from './bech32'; | ||
import { MsgVote } from './'; | ||
|
||
/** | ||
* Stores vote information for a proposal | ||
*/ | ||
export class Vote extends JSONSerializable<Vote.Data> { | ||
/** | ||
* @param proposal_id ID of proposal to vote on | ||
* @param voter voter's account address | ||
* @param option one of voting options | ||
*/ | ||
constructor( | ||
public proposal_id: number, | ||
public voter: AccAddress, | ||
public option: MsgVote.Option | ||
) { | ||
super(); | ||
} | ||
|
||
public static fromData(data: Vote.Data): Vote { | ||
const { proposal_id, voter, option } = data; | ||
return new Vote(parseInt(proposal_id), voter, option); | ||
} | ||
|
||
public toData(): Vote.Data { | ||
const { proposal_id, voter, option } = this; | ||
return { | ||
proposal_id: proposal_id.toFixed(), | ||
voter, | ||
option, | ||
}; | ||
} | ||
} | ||
|
||
export namespace Vote { | ||
export interface Data { | ||
proposal_id: string; | ||
voter: AccAddress; | ||
option: MsgVote.Option; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters