-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathassets.ts
53 lines (49 loc) · 1.42 KB
/
assets.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import type { Impl } from '.';
import { servicesCtx } from '../../ctx';
import { assetPatterns } from '@penumbra-zone/constants';
export const assets: Impl['assets'] = async function* (req, ctx) {
const services = ctx.values.get(servicesCtx);
const { indexedDb } = await services.getWalletServices();
const {
filtered,
includeLpNfts,
includeProposalNfts,
includeDelegationTokens,
includeUnbondingTokens,
includeVotingReceiptTokens,
includeSpecificDenominations,
} = req;
const patterns: {
includeReq: boolean;
pattern: RegExp;
}[] = [
{
includeReq: includeLpNfts,
pattern: assetPatterns.lpNftPattern,
},
{
includeReq: includeDelegationTokens,
pattern: assetPatterns.delegationTokenPattern,
},
{
includeReq: includeProposalNfts,
pattern: assetPatterns.proposalNftPattern,
},
{
includeReq: includeUnbondingTokens,
pattern: assetPatterns.unbondingTokenPattern,
},
{
includeReq: includeVotingReceiptTokens,
pattern: assetPatterns.votingReceiptPattern,
},
...includeSpecificDenominations.map(d => ({
includeReq: true,
pattern: new RegExp(`^${d.denom}$`),
})),
].filter(i => i.includeReq);
for await (const metadata of indexedDb.iterateAssetsMetadata()) {
if (filtered && !patterns.find(p => p.pattern.test(metadata.display))) continue;
yield { denomMetadata: metadata };
}
};