Skip to content

Commit ea312d1

Browse files
committed
feat: types
Added types for ServiceError and Utils
1 parent 4a90033 commit ea312d1

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/services/BaseService.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import axios, { AxiosError, AxiosInstance } from 'axios'
22
import { isValidChecksumAddress } from 'ethereumjs-util'
3+
import { ResponseCodes, ServiceErrorInstance } from '../types'
34

4-
class ServiceError extends Error {
5-
public code: number
6-
constructor(message: string, code: number) {
5+
class ServiceError extends Error implements ServiceErrorInstance {
6+
public code: ResponseCodes
7+
constructor(message: string, code: ResponseCodes) {
78
super(message)
89
this.code = code
910
}

src/services/Utils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Transaction } from 'web3/eth/types'
22

33
import BaseService from './BaseService'
4+
import { UtilsInstance } from '../types'
45

5-
export default class Utils extends BaseService {
6+
export default class Utils extends BaseService implements UtilsInstance {
67
constructor(token: string, apiUrl?: string) {
78
super(token, apiUrl)
89
}

src/types.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { Transaction } from 'web3/eth/types'
22

3-
export type ResponseCodes = 200 | 401 | 404 | 500 | 504
3+
export type ResponseCodes = 200 | 400 | 401 | 404 | 500 | 504
44

55
type Currency = {
66
value: string
77
description: string
88
subChoices?: Currency[]
99
}
1010

11+
export interface ServiceErrorInstance extends Error {
12+
code: ResponseCodes
13+
}
14+
1115
export interface LoanMetadata {
1216
mediums: Currency[]
1317
collaterals: Currency[]
@@ -53,6 +57,13 @@ export interface LoanAPIInstance {
5357
getMetadata(): Promise<LoanMetadata>
5458
}
5559

60+
export interface UtilsInstance {
61+
approveTransfer(address: string, tokenSymbol: string): Promise<Transaction>
62+
isTransferApproved(address: string, tokenSymbol: string, amount: number): Promise<boolean>
63+
signup(email: string, name: string, password: string, organisation?: string): Promise<string>
64+
renewToken(email: string, password: string): Promise<string>
65+
}
66+
5667
export interface MarketplaceInstance {
5768
request: LoanAPIInstance
5869
}

0 commit comments

Comments
 (0)