From fae92e548364a105d638ba976e5a2c888fc74960 Mon Sep 17 00:00:00 2001 From: jhernandezb Date: Thu, 24 Nov 2022 23:59:17 -0600 Subject: [PATCH] add update and remove discount price --- contracts/minter/contract.ts | 77 ++++++++++++++++++++++++++++ contracts/minter/messages/execute.ts | 26 ++++++++++ pages/contracts/minter/execute.tsx | 2 +- 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/contracts/minter/contract.ts b/contracts/minter/contract.ts index 328023f..f625028 100644 --- a/contracts/minter/contract.ts +++ b/contracts/minter/contract.ts @@ -43,6 +43,8 @@ export interface MinterInstance { shuffle: (senderAddress: string) => Promise withdraw: (senderAddress: string) => Promise airdrop: (senderAddress: string, recipients: string[]) => Promise + updateDiscountPrice: (senderAddress: string, price: string) => Promise + removeDiscountPrice: (senderAddress: string) => Promise } export interface MinterMessages { @@ -56,6 +58,26 @@ export interface MinterMessages { shuffle: () => ShuffleMessage withdraw: () => WithdrawMessage airdrop: (recipients: string[]) => CustomMessage + updateDiscountPrice: (price: string) => UpdateDiscountPriceMessage + removeDiscountPrice: () => RemoveDiscountPriceMessage +} + +export interface UpdateDiscountPriceMessage { + sender: string + contract: string + msg: { + update_discount_price: Record + } + funds: Coin[] +} + +export interface RemoveDiscountPriceMessage { + sender: string + contract: string + msg: { + remove_discount_price: Record + } + funds: Coin[] } export interface MintMessage { @@ -366,6 +388,35 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC return res.transactionHash } + const updateDiscountPrice = async (senderAddress: string, price: string): Promise => { + const res = await client.execute( + senderAddress, + contractAddress, + { + update_discount_price: { + price, + }, + }, + 'auto', + '', + ) + + return res.transactionHash + } + + const removeDiscountPrice = async (senderAddress: string): Promise => { + const res = await client.execute( + senderAddress, + contractAddress, + { + remove_discount_price: {}, + }, + 'auto', + '', + ) + + return res.transactionHash + } return { contractAddress, getConfig, @@ -383,6 +434,8 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC airdrop, shuffle, withdraw, + updateDiscountPrice, + removeDiscountPrice, } } @@ -539,6 +592,28 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC funds: [], } } + const updateDiscountPrice = (price: string): UpdateDiscountPriceMessage => { + return { + sender: txSigner, + contract: contractAddress, + msg: { + update_discount_price: { + price, + }, + }, + funds: [], + } + } + const removeDiscountPrice = (): RemoveDiscountPriceMessage => { + return { + sender: txSigner, + contract: contractAddress, + msg: { + remove_discount_price: {}, + }, + funds: [], + } + } return { mint, @@ -551,6 +626,8 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC airdrop, shuffle, withdraw, + updateDiscountPrice, + removeDiscountPrice, } } diff --git a/contracts/minter/messages/execute.ts b/contracts/minter/messages/execute.ts index 6883f7e..7703af1 100644 --- a/contracts/minter/messages/execute.ts +++ b/contracts/minter/messages/execute.ts @@ -12,6 +12,8 @@ export const EXECUTE_TYPES = [ 'mint_for', 'shuffle', 'withdraw', + 'update_discount_price', + 'remove_discount_price', ] as const export interface ExecuteListItem { @@ -56,6 +58,16 @@ export const EXECUTE_LIST: ExecuteListItem[] = [ name: 'Shuffle', description: `Shuffle the token IDs`, }, + { + id: 'update_discount_price', + name: 'Update Discount Price', + description: `Updates discount price`, + }, + { + id: 'remove_discount_price', + name: 'Remove Discount Price', + description: `Removes discount price`, + }, ] export interface DispatchExecuteProps { @@ -80,6 +92,8 @@ export type DispatchExecuteArgs = { | { type: Select<'mint_for'>; recipient: string; tokenId: number } | { type: Select<'shuffle'> } | { type: Select<'withdraw'> } + | { type: Select<'update_discount_price'>; price: string } + | { type: Select<'remove_discount_price'> } ) export const dispatchExecute = async (args: DispatchExecuteArgs) => { @@ -112,6 +126,12 @@ export const dispatchExecute = async (args: DispatchExecuteArgs) => { case 'withdraw': { return messages.withdraw(txSigner) } + case 'update_discount_price': { + return messages.updateDiscountPrice(txSigner, args.price === '' ? '0' : args.price) + } + case 'remove_discount_price': { + return messages.removeDiscountPrice(txSigner) + } default: { throw new Error('unknown execute type') } @@ -147,6 +167,12 @@ export const previewExecutePayload = (args: DispatchExecuteArgs) => { case 'withdraw': { return messages(contract)?.withdraw() } + case 'update_discount_price': { + return messages(contract)?.updateDiscountPrice(args.price === '' ? '0' : args.price) + } + case 'remove_discount_price': { + return messages(contract)?.removeDiscountPrice() + } default: { return {} } diff --git a/pages/contracts/minter/execute.tsx b/pages/contracts/minter/execute.tsx index 15747ec..b247229 100644 --- a/pages/contracts/minter/execute.tsx +++ b/pages/contracts/minter/execute.tsx @@ -84,7 +84,7 @@ const MinterExecutePage: NextPage = () => { const showLimitField = type === 'update_per_address_limit' const showTokenIdField = type === 'mint_for' const showRecipientField = isEitherType(type, ['mint_to', 'mint_for']) - const showPriceField = type === 'mint' + const showPriceField = isEitherType(type, ['mint', 'update_discount_price']) const messages = useMemo(() => contract?.use(contractState.value), [contract, wallet.address, contractState.value]) const payload: DispatchExecuteArgs = {