From 9c6e41a2fa862edb59442d94a86b6d756e95799d Mon Sep 17 00:00:00 2001 From: ZeroWave022 <36341766+ZeroWave022@users.noreply.github.com> Date: Fri, 21 Apr 2023 23:26:45 +0200 Subject: [PATCH] docs: Add JSDocs to multiple structures --- src/index.ts | 7 ++++--- src/structures/Amount.ts | 8 ++++++++ src/structures/CryptoCurrency.ts | 7 +++++++ src/structures/CryptoCurrencyFormat.ts | 7 +++++++ src/structures/CryptoCurrencyFormatUnits.ts | 7 +++++++ src/structures/ExchangeRate.ts | 7 +++++++ src/structures/RequestHandler.ts | 8 ++++++++ src/structures/Transaction.ts | 7 +++++++ src/structures/User.ts | 7 +++++++ src/structures/Wallet.ts | 7 +++++++ 10 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6c41b92..55a89ad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,8 +7,6 @@ import { APIRESTGetWallets, APIRESTPostTipPayload, APIRESTPostTips, - ApiTransaction, - ApiWallet, } from './types/TipccApi'; import Transaction from './structures/Transaction'; import { @@ -27,6 +25,9 @@ interface Events { ready: void; } +/** + * A tip.cc client to interact with the API. + */ export default class TipccClient extends EventEmitter { public token: string; @@ -108,7 +109,7 @@ export default class TipccClient extends EventEmitter { `Failed ${this.pollingRetries} consecutive API polls. Is the API responding?`, ); } - } while(!transactions); + } while (!transactions); // Reset pollingRetries, as it should only increment if multiple consecutive requests don't succeed if (this.pollingRetries > 0) this.pollingRetries = 0; diff --git a/src/structures/Amount.ts b/src/structures/Amount.ts index 922fa9c..48fea32 100644 --- a/src/structures/Amount.ts +++ b/src/structures/Amount.ts @@ -6,11 +6,19 @@ import { getCachedFiatCurrency, } from '../utils/CacheHandler'; +/** + * A class for storing an API amount. This can be used for either fiats or cryptocurrencies. + */ export default class Amount { public value: BigNumber; public currency?: CryptoCurrency; + /** + * Create an Amount. + * @param payload An amount from the API + * @param currencyType The type of currency + */ constructor(payload: ApiAmount, currencyType: 'fiat' | 'crypto' = 'crypto') { this.value = BigNumber(payload.value); switch (currencyType) { diff --git a/src/structures/CryptoCurrency.ts b/src/structures/CryptoCurrency.ts index 40cecd3..8efe890 100644 --- a/src/structures/CryptoCurrency.ts +++ b/src/structures/CryptoCurrency.ts @@ -1,6 +1,9 @@ import { ApiCurrency } from '../types/TipccApi'; import CryptoCurrencyFormat from './CryptoCurrencyFormat'; +/** + * A class for storing an API cryptocurrency. + */ export default class CryptoCurrency { public code: string; @@ -12,6 +15,10 @@ export default class CryptoCurrency { public format: CryptoCurrencyFormat; + /** + * Create a CryptoCurrency. + * @param payload The currency from the API + */ constructor(payload: ApiCurrency) { this.code = payload.code; this.name = payload.name; diff --git a/src/structures/CryptoCurrencyFormat.ts b/src/structures/CryptoCurrencyFormat.ts index ae2ac0d..2c182cc 100644 --- a/src/structures/CryptoCurrencyFormat.ts +++ b/src/structures/CryptoCurrencyFormat.ts @@ -1,11 +1,18 @@ import { ApiCurrencyFormat } from '../types/TipccApi'; import CryptoCurrencyUnit from './CryptoCurrencyFormatUnits'; +/** + * A class for storing an API cryptocurrency format. + */ export default class CryptoCurrencyFormat { public scale: number; public units: CryptoCurrencyUnit[]; + /** + * Create a CryptoCurrencyFormat. + * @param payload The format from the API + */ constructor(payload: ApiCurrencyFormat) { this.scale = payload.scale; this.units = payload.units.map((unit) => new CryptoCurrencyUnit(unit)); diff --git a/src/structures/CryptoCurrencyFormatUnits.ts b/src/structures/CryptoCurrencyFormatUnits.ts index 8cb1e5e..57b4d4c 100644 --- a/src/structures/CryptoCurrencyFormatUnits.ts +++ b/src/structures/CryptoCurrencyFormatUnits.ts @@ -1,5 +1,8 @@ import { ApiCurrencyFormatUnit } from '../types/TipccApi'; +/** + * A class for storing an API cryptocurrency unit. + */ export default class CryptoCurrencyUnit { public singular: string; @@ -19,6 +22,10 @@ export default class CryptoCurrencyUnit { public min: number; + /** + * Create a CryptoCurrencyUnit. + * @param payload The format unit from the API + */ constructor(payload: ApiCurrencyFormatUnit) { this.singular = payload.singular; this.plural = payload.plural ?? undefined; diff --git a/src/structures/ExchangeRate.ts b/src/structures/ExchangeRate.ts index 549a13c..30b9762 100644 --- a/src/structures/ExchangeRate.ts +++ b/src/structures/ExchangeRate.ts @@ -1,6 +1,9 @@ import { ApiRate } from '../types/TipccApi'; import Amount from './Amount'; +/** + * A class for storing an API exchange rate for a cryptocurrency. + */ export default class ExchangeRate { public code: string; @@ -8,6 +11,10 @@ export default class ExchangeRate { public usdValue?: Amount; + /** + * Create an ExchangeRate. + * @param payload The rate from the API + */ constructor(payload: ApiRate) { this.code = payload.code; this.name = payload.name; diff --git a/src/structures/RequestHandler.ts b/src/structures/RequestHandler.ts index 1a33895..dec88e8 100644 --- a/src/structures/RequestHandler.ts +++ b/src/structures/RequestHandler.ts @@ -1,6 +1,9 @@ import axios, { AxiosRequestConfig, RawAxiosResponseHeaders } from 'axios'; import Bucket from '../utils/Bucket'; +/** + * A handler used for HTTP requests. + */ export default class RequestHandler { private _apiBaseUrl: string; @@ -12,6 +15,11 @@ export default class RequestHandler { private _requestOptions: AxiosRequestConfig; + /** + * Create a RequestHandler. + * @param apiKey The tip.cc API key + * @param payload Optional: options for requests + */ constructor( apiKey: string, payload: { diff --git a/src/structures/Transaction.ts b/src/structures/Transaction.ts index b88dee9..aa1fc02 100644 --- a/src/structures/Transaction.ts +++ b/src/structures/Transaction.ts @@ -2,6 +2,9 @@ import { ApiTransaction } from '../types/TipccApi'; import Amount from './Amount'; import User from './User'; +/** + * A class for storing an API transaction. + */ export default class Transaction { public id: string; @@ -25,6 +28,10 @@ export default class Transaction { public created: Date; + /** + * Create a Transaction. + * @param payload The transaction from the API + */ constructor(payload: ApiTransaction) { this.id = payload.id; this.type = payload.type; diff --git a/src/structures/User.ts b/src/structures/User.ts index e147576..8eabe60 100644 --- a/src/structures/User.ts +++ b/src/structures/User.ts @@ -1,5 +1,8 @@ import { ApiUser } from '../types/TipccApi'; +/** + * A class for storing an API user. + */ export default class User { public identifier: string; @@ -9,6 +12,10 @@ export default class User { public service: 'discord'; + /** + * Create a User. + * @param payload The user from the API + */ constructor(payload: ApiUser) { this.identifier = payload.identifier; this.username = payload.username; diff --git a/src/structures/Wallet.ts b/src/structures/Wallet.ts index 79cb3cf..0a82f4a 100644 --- a/src/structures/Wallet.ts +++ b/src/structures/Wallet.ts @@ -1,6 +1,9 @@ import { ApiWallet } from '../types/TipccApi'; import Amount from './Amount'; +/** + * A class for storing an API wallet. + */ export default class Wallet { public code: string; @@ -10,6 +13,10 @@ export default class Wallet { public usdValue: Amount | null = null; + /** + * Create a Wallet. + * @param payload The wallet from the API + */ constructor(payload: ApiWallet) { this.code = payload.code; this.name = payload.name;