|
1 |
| -import { isAddress } from 'ethers' |
2 | 1 | import type { BlocklistAccountsQueryVariables, BlocklistAccountsQueryPayload } from '../../../../graphql/subgraph/vault'
|
3 |
| -import { apiUrls, validateArgs } from '../../../../utils' |
| 2 | +import { apiUrls } from '../../../../utils' |
4 | 3 | import graphql from '../../../../graphql'
|
5 | 4 | import { ModifiedBlocklist } from './types'
|
6 | 5 | import modifyBlocklist from './modifyBlocklist'
|
| 6 | +import { getListVariables, GetListVariablesInput } from '../../../utils' |
7 | 7 |
|
8 | 8 |
|
9 |
| -type GetBlocklistInput = { |
10 |
| - vaultAddress: string |
11 |
| - orderDirection?: BlocklistAccountsQueryVariables['orderDirection'] |
12 |
| - search?: string |
13 |
| - limit?: number |
14 |
| - skip?: number |
15 |
| - addressIn?: BlocklistAccountsQueryVariables['where']['address_in'] |
| 9 | +type GetBlocklistInput = GetListVariablesInput & { |
16 | 10 | options: StakeWise.Options
|
17 | 11 | }
|
18 | 12 |
|
19 |
| -const validateList = (addressIn: string[]) => { |
20 |
| - const isValid = addressIn.every((address) => isAddress(address)) |
21 |
| - |
22 |
| - if (!isValid) { |
23 |
| - throw new Error('The "addressIn" argument must be an array of valid addresses') |
24 |
| - } |
25 |
| -} |
26 |
| - |
27 | 13 | const getBlocklist = (input: GetBlocklistInput) => {
|
28 |
| - const { vaultAddress, orderDirection, search, limit, skip, addressIn, options } = input |
29 |
| - |
30 |
| - validateArgs.address({ vaultAddress }) |
31 |
| - |
32 |
| - if (typeof skip !== 'undefined') { |
33 |
| - validateArgs.number({ skip }) |
34 |
| - } |
35 |
| - |
36 |
| - if (typeof limit !== 'undefined') { |
37 |
| - validateArgs.number({ limit }) |
38 |
| - } |
39 |
| - |
40 |
| - if (typeof search !== 'undefined') { |
41 |
| - validateArgs.string({ search }) |
42 |
| - } |
43 |
| - |
44 |
| - if (typeof orderDirection !== 'undefined') { |
45 |
| - if (![ 'asc', 'desc' ].includes(orderDirection)) { |
46 |
| - throw new Error(`The "orderDirection" argument must be "asc" or "desc"`) |
47 |
| - } |
48 |
| - } |
49 |
| - |
50 |
| - if (typeof addressIn !== 'undefined') { |
51 |
| - validateArgs.array({ addressIn }) |
52 |
| - validateList(addressIn as string[]) |
53 |
| - } |
54 |
| - |
55 |
| - const vault = vaultAddress.toLowerCase() |
| 14 | + const { options, ...rest } = input |
56 | 15 |
|
57 |
| - const where = search |
58 |
| - ? { vault, address_in: addressIn, address_contains: search.toLowerCase() } as BlocklistAccountsQueryVariables['where'] |
59 |
| - : { vault, address_in: addressIn } as BlocklistAccountsQueryVariables['where'] |
| 16 | + const variables = getListVariables<BlocklistAccountsQueryVariables>(rest) |
60 | 17 |
|
61 | 18 | return graphql.subgraph.vault.fetchBlocklistAccountsQuery<ModifiedBlocklist>({
|
62 | 19 | url: apiUrls.getSubgraphqlUrl(options),
|
63 |
| - variables: { |
64 |
| - where, |
65 |
| - skip: skip || 0, |
66 |
| - limit: limit || 100, |
67 |
| - orderDirection: orderDirection || 'desc', |
68 |
| - }, |
| 20 | + variables, |
69 | 21 | modifyResult: (data: BlocklistAccountsQueryPayload) => modifyBlocklist({ data }),
|
70 | 22 | })
|
71 | 23 | }
|
|
0 commit comments