-
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.
Support for fund and quote_fund for wallet funding (#322)
- Loading branch information
1 parent
a6dc206
commit 16508a7
Showing
24 changed files
with
1,731 additions
and
53 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
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,99 @@ | ||
import Decimal from "decimal.js"; | ||
import { CryptoAmount as CryptoAmountModel } from "../client/api"; | ||
import { Asset } from "./asset"; | ||
|
||
/** | ||
* A representation of a CryptoAmount that includes the amount and asset. | ||
*/ | ||
export class CryptoAmount { | ||
private amount: Decimal; | ||
private assetObj: Asset; | ||
private assetId: string; | ||
|
||
/** | ||
* Creates a new CryptoAmount instance. | ||
* | ||
* @param amount - The amount of the Asset | ||
* @param asset - The Asset | ||
* @param assetId - Optional Asset ID override | ||
*/ | ||
constructor(amount: Decimal, asset: Asset, assetId?: string) { | ||
this.amount = amount; | ||
this.assetObj = asset; | ||
this.assetId = assetId || asset.getAssetId(); | ||
} | ||
|
||
/** | ||
* Converts a CryptoAmount model to a CryptoAmount. | ||
* | ||
* @param amountModel - The crypto amount from the API | ||
* @returns The converted CryptoAmount object | ||
*/ | ||
public static fromModel(amountModel: CryptoAmountModel): CryptoAmount { | ||
const asset = Asset.fromModel(amountModel.asset); | ||
return new CryptoAmount(asset.fromAtomicAmount(new Decimal(amountModel.amount)), asset); | ||
} | ||
|
||
/** | ||
* Converts a CryptoAmount model and asset ID to a CryptoAmount. | ||
* This can be used to specify a non-primary denomination that we want the amount | ||
* to be converted to. | ||
* | ||
* @param amountModel - The crypto amount from the API | ||
* @param assetId - The Asset ID of the denomination we want returned | ||
* @returns The converted CryptoAmount object | ||
*/ | ||
public static fromModelAndAssetId(amountModel: CryptoAmountModel, assetId: string): CryptoAmount { | ||
const asset = Asset.fromModel(amountModel.asset, assetId); | ||
return new CryptoAmount( | ||
asset.fromAtomicAmount(new Decimal(amountModel.amount)), | ||
asset, | ||
assetId, | ||
); | ||
} | ||
|
||
/** | ||
* Gets the amount of the Asset. | ||
* | ||
* @returns The amount of the Asset | ||
*/ | ||
public getAmount(): Decimal { | ||
return this.amount; | ||
} | ||
|
||
/** | ||
* Gets the Asset. | ||
* | ||
* @returns The Asset | ||
*/ | ||
public getAsset(): Asset { | ||
return this.assetObj; | ||
} | ||
|
||
/** | ||
* Gets the Asset ID. | ||
* | ||
* @returns The Asset ID | ||
*/ | ||
public getAssetId(): string { | ||
return this.assetId; | ||
} | ||
|
||
/** | ||
* Converts the amount to atomic units. | ||
* | ||
* @returns The amount in atomic units | ||
*/ | ||
public toAtomicAmount(): bigint { | ||
return this.assetObj.toAtomicAmount(this.amount); | ||
} | ||
|
||
/** | ||
* Returns a string representation of the CryptoAmount. | ||
* | ||
* @returns A string representation of the CryptoAmount | ||
*/ | ||
public toString(): string { | ||
return `CryptoAmount{amount: '${this.amount}', assetId: '${this.assetId}'}`; | ||
} | ||
} |
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,57 @@ | ||
import { FiatAmount as FiatAmountModel } from "../client/api"; | ||
|
||
/** | ||
* A representation of a FiatAmount that includes the amount and currency. | ||
*/ | ||
export class FiatAmount { | ||
private amount: string; | ||
private currency: string; | ||
|
||
/** | ||
* Initialize a new FiatAmount. Do not use this directly, use the fromModel method instead. | ||
* | ||
* @param amount - The amount in the fiat currency | ||
* @param currency - The currency code (e.g. 'USD') | ||
*/ | ||
constructor(amount: string, currency: string) { | ||
this.amount = amount; | ||
this.currency = currency; | ||
} | ||
|
||
/** | ||
* Convert a FiatAmount model to a FiatAmount. | ||
* | ||
* @param fiatAmountModel - The fiat amount from the API. | ||
* @returns The converted FiatAmount object. | ||
*/ | ||
public static fromModel(fiatAmountModel: FiatAmountModel): FiatAmount { | ||
return new FiatAmount(fiatAmountModel.amount, fiatAmountModel.currency); | ||
} | ||
|
||
/** | ||
* Get the amount in the fiat currency. | ||
* | ||
* @returns The amount in the fiat currency. | ||
*/ | ||
public getAmount(): string { | ||
return this.amount; | ||
} | ||
|
||
/** | ||
* Get the currency code. | ||
* | ||
* @returns The currency code. | ||
*/ | ||
public getCurrency(): string { | ||
return this.currency; | ||
} | ||
|
||
/** | ||
* Get a string representation of the FiatAmount. | ||
* | ||
* @returns A string representation of the FiatAmount. | ||
*/ | ||
public toString(): string { | ||
return `FiatAmount(amount: '${this.amount}', currency: '${this.currency}')`; | ||
} | ||
} |
Oops, something went wrong.