I had a function that returned the most recent 3 payment operations for an account. But I wante to change it so that it would only return the most recent 3 payment operations for only the asset being looked for so I tried adding a map and filter to the observable using pipes. Like so:
getJohnAccountPaymentOperationsRecent(account_id: string) {
// using .order() and .limit() to get the 3 most recent transactions(payment operations) only.
return fromPromise(this.server.operations().forAccount(account_id).order("desc").limit(3).call())
.pipe(
tap(res => console.log(res)),
map(res => res['records'].filter(r => r['type'] == 'payment' && r['asset_code'] == 'JOHN')),
)
}
The problem is this does the limit before the filtering is done so may show less than 3 transactions (or none at all if the most recent 3 transactions didn't include the asset "JOHN".
How can I apply the filter first and then limit the returned result to only 3?