stargaze-studio/contracts/whitelist/messages/query.ts
Arda Nakışçı aa42f8763a
Implement contract UIs (#2)
* Add instantiate page for minter

* Add query page to minter contract

* Add execute page for minter contract

* Add contracts index page

* Refaactor sg721 helper files

* Add instantiate page

* Add query page for sg721

* Add execute page for sg721 contract

* Copy page templates for whitelist contracts

* Add instantitate for whitelist contract

* Add query page to whitelist contract

* Add execute page for whitelist contract
2022-07-19 10:53:03 +03:00

48 lines
1.5 KiB
TypeScript

import type { WhiteListInstance } from '../contract'
export type QueryType = typeof QUERY_TYPES[number]
export const QUERY_TYPES = ['has_started', 'has_ended', 'is_active', 'members', 'has_member', 'config'] as const
export interface QueryListItem {
id: QueryType
name: string
description?: string
}
export const QUERY_LIST: QueryListItem[] = [
{ id: 'has_started', name: 'Has Started', description: 'Check if the whitelist minting has started' },
{ id: 'has_ended', name: 'Has Ended', description: 'Check if the whitelist minting has ended' },
{ id: 'is_active', name: 'Is Active', description: 'Check if the whitelist minting is active' },
{ id: 'members', name: 'Members', description: 'View the whitelist members' },
{ id: 'has_member', name: 'Has Member', description: 'Check if a member is in the whitelist' },
{ id: 'config', name: 'Config', description: 'View the whitelist configuration' },
]
export interface DispatchQueryProps {
messages: WhiteListInstance | undefined
type: QueryType
address: string
}
export const dispatchQuery = (props: DispatchQueryProps) => {
const { messages, type, address } = props
switch (type) {
case 'has_started':
return messages?.hasStarted()
case 'has_ended':
return messages?.hasEnded()
case 'is_active':
return messages?.isActive()
case 'members':
return messages?.members()
case 'has_member':
return messages?.hasMember(address)
case 'config':
return messages?.config()
default: {
throw new Error('unknown query type')
}
}
}