Skip to content

Commit

Permalink
feat: types
Browse files Browse the repository at this point in the history
Added types for ServiceError and Utils
  • Loading branch information
kyzia551 committed Feb 15, 2019
1 parent 4a90033 commit ea312d1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/services/BaseService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import axios, { AxiosError, AxiosInstance } from 'axios'
import { isValidChecksumAddress } from 'ethereumjs-util'
import { ResponseCodes, ServiceErrorInstance } from '../types'

class ServiceError extends Error {
public code: number
constructor(message: string, code: number) {
class ServiceError extends Error implements ServiceErrorInstance {
public code: ResponseCodes
constructor(message: string, code: ResponseCodes) {
super(message)
this.code = code
}
Expand Down
3 changes: 2 additions & 1 deletion src/services/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Transaction } from 'web3/eth/types'

import BaseService from './BaseService'
import { UtilsInstance } from '../types'

export default class Utils extends BaseService {
export default class Utils extends BaseService implements UtilsInstance {
constructor(token: string, apiUrl?: string) {
super(token, apiUrl)
}
Expand Down
13 changes: 12 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { Transaction } from 'web3/eth/types'

export type ResponseCodes = 200 | 401 | 404 | 500 | 504
export type ResponseCodes = 200 | 400 | 401 | 404 | 500 | 504

type Currency = {
value: string
description: string
subChoices?: Currency[]
}

export interface ServiceErrorInstance extends Error {
code: ResponseCodes
}

export interface LoanMetadata {
mediums: Currency[]
collaterals: Currency[]
Expand Down Expand Up @@ -53,6 +57,13 @@ export interface LoanAPIInstance {
getMetadata(): Promise<LoanMetadata>
}

export interface UtilsInstance {
approveTransfer(address: string, tokenSymbol: string): Promise<Transaction>
isTransferApproved(address: string, tokenSymbol: string, amount: number): Promise<boolean>
signup(email: string, name: string, password: string, organisation?: string): Promise<string>
renewToken(email: string, password: string): Promise<string>
}

export interface MarketplaceInstance {
request: LoanAPIInstance
}
Expand Down

0 comments on commit ea312d1

Please sign in to comment.