-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Balance] fetch historical balance (#147)
* [chore] Update package-lock.json (#132) * [Balance] fetch historical balance * formatting * fix lint * add max size for fetching all history * rebase error * tweak naming * address comments * move list historical balance test under address * address comment * fix lint * fix IDE change * update changelog * add struct for ListHistoricalBalancesOptions * fix format * fix lint * change log version * address comments --------- Co-authored-by: John Peterson <[email protected]>
- Loading branch information
1 parent
23d4d80
commit e38d836
Showing
10 changed files
with
3,295 additions
and
2,903 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
import Decimal from "decimal.js"; | ||
import { HistoricalBalance as HistoricalBalanceModel } from "../client"; | ||
import { Asset } from "./asset"; | ||
|
||
/** A representation of historical balance. */ | ||
export class HistoricalBalance { | ||
public readonly amount: Decimal; | ||
public readonly blockHash: string; | ||
public readonly blockHeight: Decimal; | ||
public readonly asset: Asset; | ||
|
||
/** | ||
* Private constructor to prevent direct instantiation outside of the factory methods. | ||
* | ||
* @ignore | ||
* @param {Decimal} amount - The amount of the balance. | ||
* @param {Decimal} blockHeight - The block height at which the balance was recorded. | ||
* @param {string} blockHash - The block hash at which the balance was recorded | ||
* @param {string} asset - The asset we want to fetch. | ||
* @hideconstructor | ||
*/ | ||
private constructor(amount: Decimal, blockHeight: Decimal, blockHash: string, asset: Asset) { | ||
this.amount = amount; | ||
this.blockHeight = blockHeight; | ||
this.blockHash = blockHash; | ||
this.asset = asset; | ||
} | ||
|
||
/** | ||
* Converts a HistoricalBalanceModel into a HistoricalBalance object. | ||
* | ||
* @param {HistoricalBalanceModel} model - The historical balance model object. | ||
* @returns {HistoricalBalance} The HistoricalBalance object. | ||
*/ | ||
public static fromModel(model: HistoricalBalanceModel): HistoricalBalance { | ||
const asset = Asset.fromModel(model.asset); | ||
return new HistoricalBalance( | ||
asset.fromAtomicAmount(new Decimal(model.amount)), | ||
new Decimal(model.block_height), | ||
model.block_hash, | ||
asset, | ||
); | ||
} | ||
} |
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
Oops, something went wrong.