-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [list requests] add requests * [list requests] add requests * [list requests] update list modal * [api cache] return abort request * [list requests] update requests
- Loading branch information
1 parent
bad97d4
commit bef34fa
Showing
18 changed files
with
449 additions
and
125 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
query BlocklistAccounts($where: VaultBlockedAccount_filter, $limit: Int, $skip: Int, $orderDirection: OrderDirection) { | ||
vaultBlockedAccounts(where: $where, first: $limit, skip: $skip, orderDirection: $orderDirection, orderBy: createdAt) { | ||
createdAt | ||
address | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
query WhitelistAccounts($where: PrivateVaultAccount_filter, $limit: Int, $skip: Int, $orderDirection: OrderDirection) { | ||
privateVaultAccounts(where: $where, first: $limit, skip: $skip, orderDirection: $orderDirection, orderBy: createdAt) { | ||
createdAt | ||
address | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import type { BlocklistAccountsQueryVariables, BlocklistAccountsQueryPayload } from '../../../../graphql/subgraph/vault' | ||
import { apiUrls, validateArgs } from '../../../../utils' | ||
import graphql from '../../../../graphql' | ||
import { ModifiedBlocklist } from './types' | ||
import modifyBlocklist from './modifyBlocklist' | ||
|
||
|
||
type GetBlocklistInput = { | ||
vaultAddress: string | ||
orderDirection?: BlocklistAccountsQueryVariables['orderDirection'] | ||
search?: string | ||
limit?: number | ||
skip?: number | ||
options: StakeWise.Options | ||
} | ||
|
||
type GetBlocklistOutput = { | ||
blocklist: { | ||
createdAt: number | ||
address: string | ||
}[] | ||
} | ||
|
||
const getBlocklist = async (input: GetBlocklistInput): Promise<GetBlocklistOutput> => { | ||
const { vaultAddress, orderDirection, search, limit, skip, options } = input | ||
|
||
validateArgs.address({ vaultAddress }) | ||
|
||
if (typeof skip !== 'undefined') { | ||
validateArgs.number({ skip }) | ||
} | ||
|
||
if (typeof limit !== 'undefined') { | ||
validateArgs.number({ limit }) | ||
} | ||
|
||
if (typeof search !== 'undefined') { | ||
validateArgs.string({ search }) | ||
} | ||
|
||
if (typeof orderDirection !== 'undefined') { | ||
if (![ 'asc', 'desc' ].includes(orderDirection)) { | ||
throw new Error(`The "orderDirection" argument must be "asc" or "desc"`) | ||
} | ||
} | ||
|
||
const vault = vaultAddress.toLowerCase() | ||
|
||
const where = search | ||
? { vault, address_contains: search.toLowerCase() } as BlocklistAccountsQueryVariables['where'] | ||
: { vault } as BlocklistAccountsQueryVariables['where'] | ||
|
||
return graphql.subgraph.vault.fetchBlocklistAccountsQuery<ModifiedBlocklist>({ | ||
url: apiUrls.getSubgraphqlUrl(options), | ||
variables: { | ||
where, | ||
skip: skip || 0, | ||
limit: limit || 100, | ||
orderDirection: orderDirection || 'desc', | ||
}, | ||
modifyResult: (data: BlocklistAccountsQueryPayload) => modifyBlocklist({ data }), | ||
}) | ||
} | ||
|
||
|
||
export default getBlocklist |
43 changes: 43 additions & 0 deletions
43
src/methods/vault/requests/getBlocklist/modifyBlocklist.spec.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import modifyBlocklist from './modifyBlocklist' | ||
import type { BlocklistAccountsQueryPayload } from '../../../../graphql/subgraph/vault' | ||
|
||
|
||
describe('modifyBlocklist', () => { | ||
const mockBlocklistQueryPayload: BlocklistAccountsQueryPayload = { | ||
vaultBlockedAccounts: [ | ||
{ createdAt: '1693395816', address: '0xeefffd4c23d2e8c845870e273861e7d60df49663' }, | ||
{ createdAt: '1693395816', address: '0xeefffd4c23d2e8c845870e273861e7d60df49663' }, | ||
], | ||
} | ||
|
||
it('should correctly transform the whitelist data', () => { | ||
const expectedModifiedVault = [ | ||
{ | ||
createdAt: 1693395816000, | ||
address: '0xeEFFFD4C23D2E8c845870e273861e7d60Df49663', | ||
}, | ||
{ | ||
createdAt: 1693395816000, | ||
address: '0xeEFFFD4C23D2E8c845870e273861e7d60Df49663', | ||
}, | ||
] | ||
|
||
const result = modifyBlocklist({ | ||
data: mockBlocklistQueryPayload, | ||
}) | ||
|
||
expect(result).toEqual(expectedModifiedVault) | ||
}) | ||
|
||
it('should handle empty privateVaultAccounts correctly', () => { | ||
const mockDataWithoutBlockedAccounts: BlocklistAccountsQueryPayload = { | ||
vaultBlockedAccounts: [], | ||
} | ||
|
||
const result = modifyBlocklist({ | ||
data: mockDataWithoutBlockedAccounts, | ||
}) | ||
|
||
expect(result).toEqual([]) | ||
}) | ||
}) |
Oops, something went wrong.