Update Badge Hub dashboard > Query

This commit is contained in:
Serkan Reis
2023-02-14 11:26:22 +03:00
parent 3a080daf25
commit 3ec389fc39
3 changed files with 69 additions and 16 deletions
+4 -4
View File
@@ -63,7 +63,7 @@ export interface BadgeHubInstance {
getBadge: (id: number) => Promise<any>
getBadges: (start_after?: number, limit?: number) => Promise<any>
getKey: (id: number, pubkey: string) => Promise<any>
getKeys: (id: number, start_after?: number, limit?: number) => Promise<any>
getKeys: (id: number, start_after?: string, limit?: number) => Promise<any>
//Execute
createBadge: (senderAddress: string, badge: Badge) => Promise<string>
@@ -249,14 +249,14 @@ export const badgeHub = (client: SigningCosmWasmClient, txSigner: string): Badge
return res
}
const getKey = async (id: number, key: string): Promise<any> => {
const getKey = async (id: number, pubkey: string): Promise<any> => {
const res = await client.queryContractSmart(contractAddress, {
key: { id, key },
key: { id, pubkey },
})
return res
}
const getKeys = async (id: number, start_after?: number, limit?: number): Promise<any> => {
const getKeys = async (id: number, start_after?: string, limit?: number): Promise<any> => {
const res = await client.queryContractSmart(contractAddress, {
keys: { id, start_after, limit },
})
+9 -6
View File
@@ -13,9 +13,9 @@ export interface QueryListItem {
export const QUERY_LIST: QueryListItem[] = [
{ id: 'config', name: 'Config', description: 'View current config' },
{ id: 'getBadge', name: 'Query Badge', description: 'Query a badge by ID' },
{ id: 'getBadges', name: 'Query a list of Badges', description: 'Query the list of badges' },
{ id: 'getKey', name: 'Query Key', description: 'Query a key by ID' },
{ id: 'getKeys', name: 'Query a list of Keys', description: 'Query the list of keys' },
{ id: 'getBadges', name: 'Query Badges', description: 'Query a list of badges' },
{ id: 'getKey', name: 'Query Key', description: 'Query a key by ID to see if it&apos;s whitelisted' },
{ id: 'getKeys', name: 'Query Keys', description: 'Query the list of whitelisted keys' },
]
export interface DispatchQueryProps {
@@ -23,10 +23,13 @@ export interface DispatchQueryProps {
pubkey: string
messages: BadgeHubInstance | undefined
type: QueryType
startAfterNumber: number
startAfterString: string
limit: number
}
export const dispatchQuery = (props: DispatchQueryProps) => {
const { id, pubkey, messages, type } = props
const { id, pubkey, messages, type, startAfterNumber, startAfterString, limit } = props
switch (type) {
case 'config': {
return messages?.getConfig()
@@ -35,13 +38,13 @@ export const dispatchQuery = (props: DispatchQueryProps) => {
return messages?.getBadge(id)
}
case 'getBadges': {
return messages?.getBadges()
return messages?.getBadges(startAfterNumber, limit)
}
case 'getKey': {
return messages?.getKey(id, pubkey)
}
case 'getKeys': {
return messages?.getKeys(id)
return messages?.getKeys(id, startAfterString, limit)
}
default: {
throw new Error('unknown query type')