Skip to content

Commit

Permalink
feat(loan-offer): pre production cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kyzia551 committed Mar 8, 2019
1 parent f05ec60 commit 5f9bd68
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
7 changes: 2 additions & 5 deletions src/services/BaseService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios, { AxiosError, AxiosInstance } from 'axios'
import { isValidChecksumAddress } from 'ethereumjs-util'
import { ResponseCodes, ServiceErrorInstance, LoanMetadata, LoanAPIInstanceBase } from '../types'
import { Transaction } from 'web3/eth/types';

class ServiceError extends Error implements ServiceErrorInstance {
public code: ResponseCodes
Expand All @@ -15,9 +14,8 @@ export default class BaseService {
protected readonly api: AxiosInstance
protected readonly serviceUrlRoot: string

constructor(serviceUrlRoot : string, token: string, apiUrl?: string ) {

this.serviceUrlRoot = serviceUrlRoot;
constructor(serviceUrlRoot: string, token: string, apiUrl?: string) {
this.serviceUrlRoot = serviceUrlRoot
this.api = axios.create({
baseURL: apiUrl || 'https://apikovan.aave.com/',
headers: { Authorization: `Bearer ${token}` }
Expand Down Expand Up @@ -65,5 +63,4 @@ export default class BaseService {
throw BaseService.errorHandler(e, resourceType, errorParam)
}
}

}
15 changes: 4 additions & 11 deletions src/services/LoanOffer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Transaction } from 'web3/eth/types'

import { LoanOfferAPIInstance, LoanOfferModel, LoanMetadata, BaseLoanModel } from '../types'
import { LoanOfferAPIInstance, LoanOfferModel } from '../types'
import BaseService from './BaseService'
import BaseLoanService from './BaseLoanService';
import BaseLoanService from './BaseLoanService'

export default class LoanOffer extends BaseLoanService implements LoanOfferAPIInstance {
constructor(token: string, apiUrl?: string) {
super('/offer',token, apiUrl)
super('/offer', token, apiUrl)
}

public async create(lenderAddress: string, params: LoanOfferModel): Promise<Transaction> {
Expand All @@ -33,13 +33,7 @@ export default class LoanOffer extends BaseLoanService implements LoanOfferAPIIn
public async takeLoanOffer(loanAddress: string, params: LoanOfferModel): Promise<Transaction> {
BaseService.checkAddressChecksum(loanAddress)

return await this.apiRequest(
`/take/${loanAddress}`,
'placing loan offer funds',
loanAddress,
'post',
params
)
return await this.apiRequest(`/take/${loanAddress}`, 'placing loan offer funds', loanAddress, 'post', params)
}

public async getLoanData(loanAddress: string): Promise<LoanOfferModel> {
Expand Down Expand Up @@ -67,5 +61,4 @@ export default class LoanOffer extends BaseLoanService implements LoanOfferAPIIn

return await Promise.all(allDataPromises)
}

}
9 changes: 3 additions & 6 deletions src/services/LoanRequest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Transaction } from 'web3/eth/types'

import { LoanRequestAPIInstance, BaseLoanModel, LoanRequestModel, LoanMetadata } from '../types'
import { LoanRequestAPIInstance, LoanRequestModel } from '../types'
import BaseService from './BaseService'
import BaseLoanService from './BaseLoanService';
import BaseLoanService from './BaseLoanService'

export default class LoanRequest extends BaseLoanService implements LoanRequestAPIInstance {
constructor(token: string, apiUrl?: string) {
super('/request',token, apiUrl)
super('/request', token, apiUrl)
}

public async create(borrowerWalletAddress: string, params: LoanRequestModel): Promise<Transaction> {
Expand Down Expand Up @@ -42,7 +42,6 @@ export default class LoanRequest extends BaseLoanService implements LoanRequestA
)
}


public async getLoanData(loanAddress: string): Promise<LoanRequestModel> {
BaseService.checkAddressChecksum(loanAddress)

Expand All @@ -60,7 +59,6 @@ export default class LoanRequest extends BaseLoanService implements LoanRequestA
return await Promise.all(allDataPromises)
}


public async getDataAllLoansByBorrower(borrowerAddress: string): Promise<LoanRequestModel[]> {
const requestAddressesBorrower = await this.getLoansByBorrower(borrowerAddress)
const allDataPromises = requestAddressesBorrower.map(address => this.getLoanData(address))
Expand All @@ -74,5 +72,4 @@ export default class LoanRequest extends BaseLoanService implements LoanRequestA

return await Promise.all(allDataPromises)
}

}

0 comments on commit 5f9bd68

Please sign in to comment.