Update contract helpers for sg721
This commit is contained in:
parent
fc65053978
commit
eb82d10140
@ -1,6 +1,6 @@
|
||||
import type { MsgExecuteContractEncodeObject, SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
|
||||
import { toBase64, toUtf8 } from '@cosmjs/encoding'
|
||||
import type { Coin } from '@cosmjs/stargate'
|
||||
import type { Coin, logs } from '@cosmjs/stargate'
|
||||
import { coin } from '@cosmjs/stargate'
|
||||
import { MsgExecuteContract } from 'cosmjs-types/cosmwasm/wasm/v1/tx'
|
||||
|
||||
@ -9,6 +9,11 @@ export interface InstantiateResponse {
|
||||
readonly transactionHash: string
|
||||
}
|
||||
|
||||
export interface MigrateResponse {
|
||||
readonly transactionHash: string
|
||||
readonly logs: readonly logs.Log[]
|
||||
}
|
||||
|
||||
export type Expiration = { at_height: number } | { at_time: string } | { never: Record<string, never> }
|
||||
|
||||
export interface SG721Instance {
|
||||
@ -206,6 +211,13 @@ export interface SG721Contract {
|
||||
admin?: string,
|
||||
) => Promise<InstantiateResponse>
|
||||
|
||||
migrate: (
|
||||
senderAddress: string,
|
||||
contractAddress: string,
|
||||
codeId: number,
|
||||
migrateMsg: Record<string, unknown>,
|
||||
) => Promise<MigrateResponse>
|
||||
|
||||
use: (contractAddress: string) => SG721Instance
|
||||
|
||||
messages: (contractAddress: string) => Sg721Messages
|
||||
@ -540,6 +552,19 @@ export const SG721 = (client: SigningCosmWasmClient, txSigner: string): SG721Con
|
||||
}
|
||||
}
|
||||
|
||||
const migrate = async (
|
||||
senderAddress: string,
|
||||
contractAddress: string,
|
||||
codeId: number,
|
||||
migrateMsg: Record<string, unknown>,
|
||||
): Promise<MigrateResponse> => {
|
||||
const result = await client.migrate(senderAddress, contractAddress, codeId, migrateMsg, 'auto')
|
||||
return {
|
||||
transactionHash: result.transactionHash,
|
||||
logs: result.logs,
|
||||
}
|
||||
}
|
||||
|
||||
const instantiate = async (
|
||||
senderAddress: string,
|
||||
codeId: number,
|
||||
@ -734,5 +759,5 @@ export const SG721 = (client: SigningCosmWasmClient, txSigner: string): SG721Con
|
||||
}
|
||||
}
|
||||
|
||||
return { use, instantiate, messages }
|
||||
return { use, instantiate, migrate, messages }
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ import type { Coin } from '@cosmjs/proto-signing'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import type { SG721Contract, SG721Instance, Sg721Messages } from './contract'
|
||||
import type { MigrateResponse, SG721Contract, SG721Instance, Sg721Messages } from './contract'
|
||||
import { SG721 as initContract } from './contract'
|
||||
|
||||
interface InstantiateResponse {
|
||||
@ -18,6 +18,7 @@ export interface UseSG721ContractProps {
|
||||
admin?: string,
|
||||
funds?: Coin[],
|
||||
) => Promise<InstantiateResponse>
|
||||
migrate: (contractAddress: string, codeId: number, migrateMsg: Record<string, unknown>) => Promise<MigrateResponse>
|
||||
use: (customAddress: string) => SG721Instance | undefined
|
||||
updateContractAddress: (contractAddress: string) => void
|
||||
messages: (contractAddress: string) => Sg721Messages | undefined
|
||||
@ -55,6 +56,19 @@ export function useSG721Contract(): UseSG721ContractProps {
|
||||
[SG721, wallet],
|
||||
)
|
||||
|
||||
const migrate = useCallback(
|
||||
(contractAddress: string, codeId: number, migrateMsg: Record<string, unknown>): Promise<MigrateResponse> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!SG721) {
|
||||
reject(new Error('Contract is not initialized.'))
|
||||
return
|
||||
}
|
||||
SG721.migrate(wallet.address, contractAddress, codeId, migrateMsg).then(resolve).catch(reject)
|
||||
})
|
||||
},
|
||||
[SG721, wallet],
|
||||
)
|
||||
|
||||
const use = useCallback(
|
||||
(customAddress = ''): SG721Instance | undefined => {
|
||||
return SG721?.use(address || customAddress)
|
||||
@ -74,5 +88,6 @@ export function useSG721Contract(): UseSG721ContractProps {
|
||||
use,
|
||||
updateContractAddress,
|
||||
messages,
|
||||
migrate,
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user