Skip to content

Commit 6f7c6c0

Browse files
committed
feat: Added methods to get loans data by borrower and lender address
1 parent 9b9bfb0 commit 6f7c6c0

File tree

3 files changed

+66
-41
lines changed

3 files changed

+66
-41
lines changed

README.md

+17-9
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,28 @@ const allRequestsAddresses = await marketplace.requests.getAllAddresses();
123123
const requestsData = await marketplace.requests.getDataAllLoans();
124124
```
125125

126+
 
127+
### - Get the data of a loan request by ethereum address
128+
```javascript
129+
const loanRequestAddress = "0x94D5E24B4c3cb244b9E48eB33AE6ccAD6b715456";
130+
const loanRequestData = await marketplace.requests.getLoanData(loanRequestAddress);
131+
```
132+
126133
 
127134
### - Get the data of all requests by borrower ethereum address
128135
```javascript
129-
const borrowerAddress = "0x94D5E24B4c3cb244b9E48eB33AE6ccAD6b715456"; // The address to filter
130-
// First we get the Ethereum addresses of all borrower requests
131-
const requestsAddressesByBorrower = await marketplace.requests.getLoansByBorrower(borrowerAddress);
132-
133-
const requestsData = [];
134-
for (const requestAddress of requestsAddressesByBorrower) {
135-
const data = await marketplace.requests.getLoanData(requestAddress);
136-
requestsData.push(data);
137-
}
136+
const borrowerAddress = "0x94D5E24B4c3cb244b9E48eB33AE6ccAD6b715456";
137+
const requestsAddressesByBorrower = await marketplace.requests.getDataAllLoansByBorrower(borrowerAddress);
138138
```
139139

140+
 
141+
### - Get the data of all requests by lender ethereum address
142+
```javascript
143+
const lenderAddress = "0x94D5E24B4c3cb244b9E48eB33AE6ccAD6b715456";
144+
const requestsAddressesByLender = await marketplace.requests.getDataAllLoansByLender(lenderAddress);
145+
```
146+
147+
140148
 
141149
### - Get the marketplace metadata
142150
This data will be necessary to know, for example, the symbols of the available collaterals and mediums (loan currencies) in the platform.

package-lock.json

+32-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/services/LoanRequest.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ export default class LoanRequest extends BaseService implements LoanAPIInstance
9393
}
9494

9595
public async getDataAllLoans(): Promise<LoanRequestModel[]> {
96-
const allRequestAddresses : string[] = await this.getAllAddresses();
97-
const allDataPromises = allRequestAddresses.map(address => this.getLoanData(address))
96+
const allRequestAddresses: string[] = await this.getAllAddresses()
97+
const allDataPromises = allRequestAddresses.map(address => this.getLoanData(address))
9898

99-
return await Promise.all(allDataPromises);
99+
return await Promise.all(allDataPromises)
100100
}
101101

102102
public async getLoansByBorrower(borrowerAddress: string): Promise<string[]> {
@@ -115,6 +115,20 @@ export default class LoanRequest extends BaseService implements LoanAPIInstance
115115
return await this.apiRequest(`/request/getlistbylender/${lenderAddress}`, 'loan addresses by lender', lenderAddress)
116116
}
117117

118+
public async getDataAllLoansByBorrower(borrowerAddress: string): Promise<LoanRequestModel[]> {
119+
const requestAddressesBorrower = await this.getLoansByBorrower(borrowerAddress)
120+
const allDataPromises = requestAddressesBorrower.map(address => this.getLoanData(address))
121+
122+
return await Promise.all(allDataPromises)
123+
}
124+
125+
public async getDataAllLoansByLender(lenderAddress: string): Promise<LoanRequestModel[]> {
126+
const requestAddressesLender = await this.getLoansByBorrower(lenderAddress)
127+
const allDataPromises = requestAddressesLender.map(address => this.getLoanData(address))
128+
129+
return await Promise.all(allDataPromises)
130+
}
131+
118132
public async getMetadata(): Promise<LoanMetadata> {
119133
return await this.apiRequest('/request/metadata', 'loan requests metadata')
120134
}

0 commit comments

Comments
 (0)