Skip to content

Commit

Permalink
US-2041 Added a fetch all to rif wallet services fetcher, and also ad…
Browse files Browse the repository at this point in the history
…ded prices to the return type of the init RifWalletServicesSocket.ts (#105)

Co-authored-by: Jesse Clark <[email protected]>
  • Loading branch information
Freshenext and jessgusclark authored Dec 18, 2023
1 parent 195e375 commit 8119aea
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/rifWalletServices/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsksmart/rif-wallet-services",
"version": "1.1.2",
"version": "1.2.0",
"description": "RIF Wallet Services library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
10 changes: 10 additions & 0 deletions packages/rifWalletServices/src/RifWalletServicesFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
FetchBalancesTransactionsPricesByAddressFunction,
FetchBalancesTransactionsPricesByAddressFunctionResult,
IRegisteredDappsGroup,
ITokenWithBalance, IXPubBalanceData,
RifWalletFetcherDependencies, RIFWalletServicesFetcherInterface,
Expand Down Expand Up @@ -83,6 +85,14 @@ export class RifWalletServicesFetcher implements RIFWalletServicesFetcherInterfa
return response.data
}

fetchBalancesTransactionsPricesByAddress = async ({ address, prev, next, blockNumber = '0', limit }: FetchBalancesTransactionsPricesByAddressFunction) => {
const addressLowerCase = address.toLowerCase()
const url = `/address/${addressLowerCase}/all`
const promise = this.axiosInstance.get<FetchBalancesTransactionsPricesByAddressFunctionResult>(url, { params: { prev, next, blockNumber, limit } })
const response = await this.retryPromise(promise, 2)
return response.data
}

fetchDapps = (): Promise<IRegisteredDappsGroup[]> =>
this.axiosInstance
.get<IRegisteredDappsGroup[]>('/dapps')
Expand Down
11 changes: 2 additions & 9 deletions packages/rifWalletServices/src/RifWalletServicesSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,7 @@ export class RifWalletServicesSocket
const blockNumber = this.cache.get(cacheBlockNumberText) || '0'
const catchedTxs = this.cache.get(cacheTxsText) || []

const [fetchedTokens, fetchedTransactions] = await Promise.all([
fetcher.fetchTokensByAddress(address),
fetcher.fetchTransactionsByAddress(
address,
null,
null,
blockNumber,
)
])
const { prices, tokens: fetchedTokens, transactions: fetchedTransactions } = await fetcher.fetchBalancesTransactionsPricesByAddress({ address, blockNumber })

let lastBlockNumber = blockNumber
const activityTransactions = await Promise.all(
Expand Down Expand Up @@ -103,6 +95,7 @@ export class RifWalletServicesSocket
this.emit('init', {
transactions: transactions,
balances: fetchedTokens,
prices,
})
}

Expand Down
14 changes: 14 additions & 0 deletions packages/rifWalletServices/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,17 @@ export type RifWalletSocketDependencies = {
onBeforeInit: OnBeforeInitFunction
onEnhanceTransaction: EnhanceTransactionFunction
}

export interface FetchBalancesTransactionsPricesByAddressFunction {
address: string
blockNumber?: string
prev?: string
next?: string
limit?: string
}

export interface FetchBalancesTransactionsPricesByAddressFunctionResult {
tokens: ITokenWithBalance[]
prices: Record<string, { price: number, lastUpdated: string }>
transactions: TransactionsServerResponse
}

0 comments on commit 8119aea

Please sign in to comment.