Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
APIRESTGetWallets,
APIRESTPostTipPayload,
APIRESTPostTips,
ApiTransaction,
ApiWallet,
} from './types/TipccApi';
import Transaction from './structures/Transaction';
import {
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/structures/Amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/structures/CryptoCurrency.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/structures/CryptoCurrencyFormat.ts
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
7 changes: 7 additions & 0 deletions src/structures/CryptoCurrencyFormatUnits.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ApiCurrencyFormatUnit } from '../types/TipccApi';

/**
* A class for storing an API cryptocurrency unit.
*/
export default class CryptoCurrencyUnit {
public singular: string;

Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/structures/ExchangeRate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
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;

public name: string;

public usdValue?: Amount;

/**
* Create an ExchangeRate.
* @param payload The rate from the API
*/
constructor(payload: ApiRate) {
this.code = payload.code;
this.name = payload.name;
Expand Down
8 changes: 8 additions & 0 deletions src/structures/RequestHandler.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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: {
Expand Down
7 changes: 7 additions & 0 deletions src/structures/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/structures/User.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ApiUser } from '../types/TipccApi';

/**
* A class for storing an API user.
*/
export default class User {
public identifier: string;

Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/structures/Wallet.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand Down