Skip to content

Commit

Permalink
Fixed transfer NFT with smart contract msg action.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Nov 9, 2023
1 parent a162e6b commit 1f9ee0a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
10 changes: 6 additions & 4 deletions packages/stateful/actions/core/nfts/TransferNft/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { toBase64, toUtf8 } from '@cosmjs/encoding'
import { useCallback } from 'react'
import { useFormContext } from 'react-hook-form'
import { constSelector, useRecoilValue } from 'recoil'
Expand All @@ -18,6 +17,7 @@ import {
import {
combineLoadingDataWithErrors,
decodePolytoneExecuteMsg,
encodeMessageAsBase64,
makeWasmMessage,
maybeMakePolytoneExecuteMessage,
objectMatchesStructure,
Expand Down Expand Up @@ -78,7 +78,7 @@ const useTransformToCosmos: UseTransformToCosmos<TransferNftData> = () => {
? {
send_nft: {
contract: recipient,
msg: toBase64(toUtf8(JSON.stringify(smartContractMsg))),
msg: encodeMessageAsBase64(smartContractMsg),
token_id: tokenId,
},
}
Expand Down Expand Up @@ -156,8 +156,10 @@ const useDecodedCosmosMsg: UseDecodedCosmosMsg<TransferNftData> = (
recipient: msg.wasm.execute.msg.send_nft.contract,

executeSmartContract: true,
smartContractMsg: parseEncodedMessage(
msg.wasm.execute.msg.send_nft.msg
smartContractMsg: JSON.stringify(
parseEncodedMessage(msg.wasm.execute.msg.send_nft.msg),
null,
2
),
},
}
Expand Down
5 changes: 2 additions & 3 deletions packages/utils/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import { toBase64, toUtf8 } from '@cosmjs/encoding'
import { Coin, SigningStargateClient } from '@cosmjs/stargate'
import { findAttribute, parseRawLog } from '@cosmjs/stargate/build/logs'

import { ContractVersion } from '@dao-dao/types'

import { CHAIN_GAS_MULTIPLIER } from './constants'
import { cwMsgToEncodeObject } from './messages'
import { cwMsgToEncodeObject, encodeMessageAsBase64 } from './messages'

const CONTRACT_VERSIONS = Object.values(ContractVersion)

Expand Down Expand Up @@ -55,7 +54,7 @@ export const instantiateSmartContract = async (
wasm: {
instantiate: {
code_id: codeId,
msg: toBase64(toUtf8(JSON.stringify(msg))),
msg: encodeMessageAsBase64(msg),
funds: funds || [],
label,
// Replace empty string with undefined.
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/messages/cw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { getSupportedChainConfig } from '../chain'
import { POLYTONE_TIMEOUT_SECONDS } from '../constants'
import { objectMatchesStructure } from '../objectMatchesStructure'
import { parseEncodedMessage } from './encoding'
import { encodeMessageAsBase64, parseEncodedMessage } from './encoding'
import { decodeStargateMessage } from './protobuf'

type WasmMsgType =
Expand Down Expand Up @@ -147,7 +147,7 @@ export const makeExecutableMintMessage = (
wasm: {
execute: {
contract_addr: contractAddress,
msg: toBase64(toUtf8(JSON.stringify(msg))),
msg: encodeMessageAsBase64(msg),
funds: [],
},
},
Expand Down

0 comments on commit 1f9ee0a

Please sign in to comment.