-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
137db6c
commit af2781d
Showing
1 changed file
with
31 additions
and
12 deletions.
There are no files selected for viewing
43 changes: 31 additions & 12 deletions
43
packages/router/src/grpc/view-protocol-server/unbonding-tokens-by-address-index/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
import { BalancesRequest } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb'; | ||
import { | ||
BalancesRequest, | ||
UnbondingTokensByAddressIndexRequest_Filter, | ||
UnbondingTokensByAddressIndexResponse, | ||
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb'; | ||
import { Impl } from '..'; | ||
import { balances } from '../balances'; | ||
import Array from '@penumbra-zone/polyfills/src/Array.fromAsync'; | ||
import { isUnbondingTokenBalance } from './helpers'; | ||
import { getIsClaimable, isUnbondingTokenBalance } from './helpers'; | ||
|
||
export const unbondingTokensByAddressIndex: Impl['unbondingTokensByAddressIndex'] = async ( | ||
req, | ||
ctx, | ||
) => { | ||
const allBalances = await Array.fromAsync( | ||
balances(new BalancesRequest({ accountFilter: { account: 0 } }), ctx), | ||
); | ||
export const unbondingTokensByAddressIndex: Impl['unbondingTokensByAddressIndex'] = | ||
async function* (req, ctx) { | ||
for await (const balancesResponse of balances( | ||
new BalancesRequest({ accountFilter: req.addressIndex }), | ||
ctx, | ||
)) { | ||
if (!isUnbondingTokenBalance(balancesResponse)) continue; | ||
const claimable = await getIsClaimable(balancesResponse, ctx); | ||
|
||
const unbondingTokenBalances = allBalances.filter(isUnbondingTokenBalance); | ||
}; | ||
if (req.filter === UnbondingTokensByAddressIndexRequest_Filter.CLAIMABLE && !claimable) { | ||
continue; | ||
} | ||
|
||
if ( | ||
req.filter === UnbondingTokensByAddressIndexRequest_Filter.NOT_YET_CLAIMABLE && | ||
claimable | ||
) { | ||
continue; | ||
} | ||
|
||
yield new UnbondingTokensByAddressIndexResponse({ | ||
claimable, | ||
valueView: balancesResponse.balanceView, | ||
}); | ||
} | ||
}; |