Use Cosmos Kit with Keplr Extension support.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { toUtf8 } from '@cosmjs/encoding'
|
||||
import clsx from 'clsx'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import React, { useState } from 'react'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import { SG721_NAME_ADDRESS } from 'utils/constants'
|
||||
@@ -8,6 +7,7 @@ import { csvToArray } from 'utils/csvToArray'
|
||||
import type { AirdropAllocation } from 'utils/isValidAccountsFile'
|
||||
import { isValidAccountsFile } from 'utils/isValidAccountsFile'
|
||||
import { isValidAddress } from 'utils/isValidAddress'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
interface AirdropUploadProps {
|
||||
onChange: (data: AirdropAllocation[]) => void
|
||||
@@ -22,8 +22,10 @@ export const AirdropUpload = ({ onChange }: AirdropUploadProps) => {
|
||||
await new Promise((resolve) => {
|
||||
let i = 0
|
||||
allocationData.map(async (data) => {
|
||||
if (!wallet.client) throw new Error('Wallet not connected')
|
||||
await wallet.client
|
||||
if (!wallet.isWalletConnected) throw new Error('Wallet not connected')
|
||||
await (
|
||||
await wallet.getCosmWasmClient()
|
||||
)
|
||||
.queryContractRaw(
|
||||
SG721_NAME_ADDRESS,
|
||||
toUtf8(
|
||||
|
||||
@@ -5,8 +5,8 @@ import { toUtf8 } from '@cosmjs/encoding'
|
||||
import clsx from 'clsx'
|
||||
import React, { useState } from 'react'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { useWallet } from '../contexts/wallet'
|
||||
import { SG721_NAME_ADDRESS } from '../utils/constants'
|
||||
import { isValidAddress } from '../utils/isValidAddress'
|
||||
|
||||
@@ -22,8 +22,10 @@ export const BadgeAirdropListUpload = ({ onChange }: BadgeAirdropListUploadProps
|
||||
await new Promise((resolve) => {
|
||||
let i = 0
|
||||
names.map(async (name) => {
|
||||
if (!wallet.client) throw new Error('Wallet not connected')
|
||||
await wallet.client
|
||||
if (!wallet.isWalletConnected) throw new Error('Wallet not connected')
|
||||
await (
|
||||
await wallet.getCosmWasmClient()
|
||||
)
|
||||
.queryContractRaw(
|
||||
SG721_NAME_ADDRESS,
|
||||
toUtf8(
|
||||
|
||||
@@ -6,13 +6,13 @@ import { Anchor } from 'components/Anchor'
|
||||
import type { Timezone } from 'contexts/globalSettings'
|
||||
import { setTimezone } from 'contexts/globalSettings'
|
||||
import { setLogItemList, useLogStore } from 'contexts/log'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import Link from 'next/link'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useEffect } from 'react'
|
||||
import { FaCog } from 'react-icons/fa'
|
||||
// import BrandText from 'public/brand/brand-text.svg'
|
||||
import { footerLinks, socialsLinks } from 'utils/links'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { BADGE_HUB_ADDRESS, BASE_FACTORY_ADDRESS, NETWORK, OPEN_EDITION_FACTORY_ADDRESS } from '../utils/constants'
|
||||
import { Conditional } from './Conditional'
|
||||
@@ -268,7 +268,7 @@ export const Sidebar = () => {
|
||||
</label>
|
||||
</div>
|
||||
{/* Stargaze network status */}
|
||||
<div className="text-sm capitalize">Network: {wallet.network}</div>
|
||||
<div className="text-sm capitalize">Network: {wallet.chain.pretty_name}</div>
|
||||
|
||||
{/* footer reference links */}
|
||||
<ul className="text-sm list-disc list-inside">
|
||||
|
||||
+38
-13
@@ -1,36 +1,61 @@
|
||||
import type { Coin } from '@cosmjs/proto-signing'
|
||||
import { Popover, Transition } from '@headlessui/react'
|
||||
import clsx from 'clsx'
|
||||
import { useWallet, useWalletStore } from 'contexts/wallet'
|
||||
import { Fragment } from 'react'
|
||||
import { Fragment, useEffect, useState } from 'react'
|
||||
import { FaCopy, FaPowerOff, FaRedo } from 'react-icons/fa'
|
||||
import { copy } from 'utils/clipboard'
|
||||
import { convertDenomToReadable } from 'utils/convertDenomToReadable'
|
||||
import { getShortAddress } from 'utils/getShortAddress'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { WalletButton } from './WalletButton'
|
||||
import { WalletPanelButton } from './WalletPanelButton'
|
||||
|
||||
export const WalletLoader = () => {
|
||||
const { address, balance, connect, disconnect, initializing: isLoading, initialized: isReady } = useWallet()
|
||||
const {
|
||||
address = '',
|
||||
username,
|
||||
connect,
|
||||
disconnect,
|
||||
isWalletConnecting,
|
||||
isWalletConnected,
|
||||
getStargateClient,
|
||||
} = useWallet()
|
||||
|
||||
const displayName = useWalletStore((store) => store.name || getShortAddress(store.address))
|
||||
// Once wallet connects, load balances.
|
||||
const [balances, setBalances] = useState<readonly Coin[] | undefined>()
|
||||
useEffect(() => {
|
||||
if (!isWalletConnected) {
|
||||
setBalances(undefined)
|
||||
return
|
||||
}
|
||||
|
||||
const loadBalances = async () => {
|
||||
const client = await getStargateClient()
|
||||
setBalances(await client.getAllBalances(address))
|
||||
}
|
||||
|
||||
loadBalances().catch(console.error)
|
||||
}, [isWalletConnected, getStargateClient, address])
|
||||
|
||||
return (
|
||||
<Popover className="mt-4 mb-2">
|
||||
{({ close }) => (
|
||||
<>
|
||||
<div className="grid -mx-4">
|
||||
{!isReady && (
|
||||
<WalletButton className="w-full" isLoading={isLoading} onClick={() => void connect()}>
|
||||
{isWalletConnected ? (
|
||||
<Popover.Button as={WalletButton} className="w-full">
|
||||
{username || address}
|
||||
</Popover.Button>
|
||||
) : (
|
||||
<WalletButton
|
||||
className="w-full"
|
||||
isLoading={isWalletConnecting}
|
||||
onClick={() => void connect().catch(console.error)}
|
||||
>
|
||||
Connect Wallet
|
||||
</WalletButton>
|
||||
)}
|
||||
|
||||
{isReady && (
|
||||
<Popover.Button as={WalletButton} className="w-full" isLoading={isLoading}>
|
||||
{displayName}
|
||||
</Popover.Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Transition
|
||||
@@ -54,7 +79,7 @@ export const WalletLoader = () => {
|
||||
{getShortAddress(address)}
|
||||
</span>
|
||||
<div className="font-bold">Your Balances</div>
|
||||
{balance.map((val) => (
|
||||
{balances?.map((val) => (
|
||||
<span key={`balance-${val.denom}`}>
|
||||
{convertDenomToReadable(val.amount)} {val.denom.slice(1, val.denom.length)}
|
||||
</span>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// Styles required for @cosmos-kit/react modal
|
||||
import '@interchain-ui/react/styles'
|
||||
|
||||
import { GasPrice } from '@cosmjs/stargate'
|
||||
import { wallets as keplrExtensionWallets } from '@cosmos-kit/keplr-extension'
|
||||
import { ChainProvider } from '@cosmos-kit/react'
|
||||
import { assets, chains } from 'chain-registry'
|
||||
import { getConfig } from 'config'
|
||||
import type { ReactNode } from 'react'
|
||||
import { NETWORK } from 'utils/constants'
|
||||
|
||||
export const WalletProvider = ({ children }: { children: ReactNode }) => {
|
||||
const { gasPrice, feeToken } = getConfig(NETWORK)
|
||||
return (
|
||||
<ChainProvider
|
||||
assetLists={assets}
|
||||
chains={chains}
|
||||
signerOptions={{
|
||||
signingCosmwasm: () => ({
|
||||
gasPrice: GasPrice.fromString(`${gasPrice}${feeToken}`),
|
||||
}),
|
||||
signingStargate: () => ({
|
||||
gasPrice: GasPrice.fromString(`${gasPrice}${feeToken}`),
|
||||
}),
|
||||
}}
|
||||
wallets={keplrExtensionWallets}
|
||||
>
|
||||
{children}
|
||||
</ChainProvider>
|
||||
)
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import { toUtf8 } from '@cosmjs/encoding'
|
||||
import clsx from 'clsx'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import React, { useState } from 'react'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import { SG721_NAME_ADDRESS } from 'utils/constants'
|
||||
import { csvToFlexList } from 'utils/csvToFlexList'
|
||||
import { isValidAddress } from 'utils/isValidAddress'
|
||||
import { isValidFlexListFile } from 'utils/isValidFlexListFile'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
export interface WhitelistFlexMember {
|
||||
address: string
|
||||
@@ -26,8 +26,10 @@ export const WhitelistFlexUpload = ({ onChange }: WhitelistFlexUploadProps) => {
|
||||
await new Promise((resolve) => {
|
||||
let i = 0
|
||||
memberData.map(async (data) => {
|
||||
if (!wallet.client) throw new Error('Wallet not connected')
|
||||
await wallet.client
|
||||
if (!wallet.isWalletConnected) throw new Error('Wallet not connected')
|
||||
await (
|
||||
await wallet.getCosmWasmClient()
|
||||
)
|
||||
.queryContractRaw(
|
||||
SG721_NAME_ADDRESS,
|
||||
toUtf8(
|
||||
|
||||
@@ -5,8 +5,8 @@ import { toUtf8 } from '@cosmjs/encoding'
|
||||
import clsx from 'clsx'
|
||||
import React, { useState } from 'react'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { useWallet } from '../contexts/wallet'
|
||||
import { SG721_NAME_ADDRESS } from '../utils/constants'
|
||||
import { isValidAddress } from '../utils/isValidAddress'
|
||||
|
||||
@@ -22,8 +22,10 @@ export const WhitelistUpload = ({ onChange }: WhitelistUploadProps) => {
|
||||
await new Promise((resolve) => {
|
||||
let i = 0
|
||||
names.map(async (name) => {
|
||||
if (!wallet.client) throw new Error('Wallet not connected')
|
||||
await wallet.client
|
||||
if (!wallet.isWalletConnected) throw new Error('Wallet not connected')
|
||||
await (
|
||||
await wallet.getCosmWasmClient()
|
||||
)
|
||||
.queryContractRaw(
|
||||
SG721_NAME_ADDRESS,
|
||||
toUtf8(
|
||||
|
||||
@@ -20,7 +20,6 @@ import { useMetadataAttributesState } from 'components/forms/MetadataAttributes.
|
||||
import { JsonPreview } from 'components/JsonPreview'
|
||||
import { TransactionHash } from 'components/TransactionHash'
|
||||
import { WhitelistUpload } from 'components/WhitelistUpload'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import type { Badge, BadgeHubInstance } from 'contracts/badgeHub'
|
||||
import sizeof from 'object-sizeof'
|
||||
import type { FormEvent } from 'react'
|
||||
@@ -32,6 +31,7 @@ import * as secp256k1 from 'secp256k1'
|
||||
import { generateKeyPairs, sha256 } from 'utils/hash'
|
||||
import { isValidAddress } from 'utils/isValidAddress'
|
||||
import { resolveAddress } from 'utils/resolveAddress'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { BadgeAirdropListUpload } from '../../BadgeAirdropListUpload'
|
||||
import { AddressInput, NumberInput, TextInput } from '../../forms/FormInput'
|
||||
@@ -266,7 +266,7 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage
|
||||
nft: nftState.value,
|
||||
badgeHubMessages,
|
||||
badgeHubContract: badgeHubContractAddress,
|
||||
txSigner: wallet.address,
|
||||
txSigner: wallet.address || '',
|
||||
type,
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage
|
||||
|
||||
const { isLoading, mutate } = useMutation(
|
||||
async (event: FormEvent) => {
|
||||
if (!wallet.client) {
|
||||
if (!wallet.isWalletConnected) {
|
||||
throw new Error('Please connect your wallet.')
|
||||
}
|
||||
event.preventDefault()
|
||||
@@ -412,8 +412,10 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage
|
||||
throw new Error('Please enter a valid private key.')
|
||||
}
|
||||
|
||||
if (wallet.client && type === 'edit_badge') {
|
||||
const feeRateRaw = await wallet.client.queryContractRaw(
|
||||
if (type === 'edit_badge') {
|
||||
const feeRateRaw = await (
|
||||
await wallet.getCosmWasmClient()
|
||||
).queryContractRaw(
|
||||
badgeHubContractAddress,
|
||||
toUtf8(Buffer.from(Buffer.from('fee_rate').toString('hex'), 'hex').toString()),
|
||||
)
|
||||
@@ -421,7 +423,9 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage
|
||||
|
||||
await toast
|
||||
.promise(
|
||||
wallet.client.queryContractSmart(badgeHubContractAddress, {
|
||||
(
|
||||
await wallet.getCosmWasmClient()
|
||||
).queryContractSmart(badgeHubContractAddress, {
|
||||
badge: { id: badgeId },
|
||||
}),
|
||||
{
|
||||
|
||||
@@ -12,12 +12,12 @@ import { useInputState, useNumberInputState } from 'components/forms/FormInput.h
|
||||
import { useMetadataAttributesState } from 'components/forms/MetadataAttributes.hooks'
|
||||
import { InputDateTime } from 'components/InputDateTime'
|
||||
import { useGlobalSettings } from 'contexts/globalSettings'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import type { Trait } from 'contracts/badgeHub'
|
||||
import type { ChangeEvent } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import { BADGE_HUB_ADDRESS } from 'utils/constants'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { AddressInput, NumberInput, TextInput } from '../../forms/FormInput'
|
||||
import { MetadataAttributes } from '../../forms/MetadataAttributes'
|
||||
@@ -47,7 +47,7 @@ export interface BadgeDetailsDataProps {
|
||||
}
|
||||
|
||||
export const BadgeDetails = ({ metadataSize, onChange, uploadMethod }: BadgeDetailsProps) => {
|
||||
const wallet = useWallet()
|
||||
const { address = '', isWalletConnected, getCosmWasmClient } = useWallet()
|
||||
const { timezone } = useGlobalSettings()
|
||||
const [timestamp, setTimestamp] = useState<Date | undefined>(undefined)
|
||||
const [transferrable, setTransferrable] = useState<boolean>(false)
|
||||
@@ -61,7 +61,7 @@ export const BadgeDetails = ({ metadataSize, onChange, uploadMethod }: BadgeDeta
|
||||
name: 'manager',
|
||||
title: 'Manager',
|
||||
subtitle: 'Badge Hub Manager',
|
||||
defaultValue: wallet.address ? wallet.address : '',
|
||||
defaultValue: address,
|
||||
})
|
||||
|
||||
const nameState = useInputState({
|
||||
@@ -247,8 +247,10 @@ export const BadgeDetails = ({ metadataSize, onChange, uploadMethod }: BadgeDeta
|
||||
useEffect(() => {
|
||||
const retrieveFeeRate = async () => {
|
||||
try {
|
||||
if (wallet.client) {
|
||||
const feeRateRaw = await wallet.client.queryContractRaw(
|
||||
if (isWalletConnected) {
|
||||
const feeRateRaw = await (
|
||||
await getCosmWasmClient()
|
||||
).queryContractRaw(
|
||||
BADGE_HUB_ADDRESS,
|
||||
toUtf8(Buffer.from(Buffer.from('fee_rate').toString('hex'), 'hex').toString()),
|
||||
)
|
||||
@@ -263,7 +265,7 @@ export const BadgeDetails = ({ metadataSize, onChange, uploadMethod }: BadgeDeta
|
||||
}
|
||||
}
|
||||
void retrieveFeeRate()
|
||||
}, [wallet.client])
|
||||
}, [isWalletConnected, getCosmWasmClient])
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
@@ -10,7 +10,6 @@ import type { BadgeHubInstance } from 'contracts/badgeHub'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import { useQuery } from 'react-query'
|
||||
|
||||
import { useWallet } from '../../../contexts/wallet'
|
||||
import type { MintRule } from '../creation/ImageUploadDetails'
|
||||
|
||||
interface BadgeQueriesProps {
|
||||
@@ -20,8 +19,6 @@ interface BadgeQueriesProps {
|
||||
mintRule: MintRule
|
||||
}
|
||||
export const BadgeQueries = ({ badgeHubContractAddress, badgeId, badgeHubMessages, mintRule }: BadgeQueriesProps) => {
|
||||
const wallet = useWallet()
|
||||
|
||||
const comboboxState = useQueryComboboxState()
|
||||
const type = comboboxState.value?.id
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import { JsonPreview } from 'components/JsonPreview'
|
||||
import { Tooltip } from 'components/Tooltip'
|
||||
import { TransactionHash } from 'components/TransactionHash'
|
||||
import { useGlobalSettings } from 'contexts/globalSettings'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import type { BaseMinterInstance } from 'contracts/baseMinter'
|
||||
import type { OpenEditionMinterInstance } from 'contracts/openEditionMinter'
|
||||
import type { RoyaltyRegistryInstance } from 'contracts/royaltyRegistry'
|
||||
@@ -32,6 +31,7 @@ import { useMutation } from 'react-query'
|
||||
import { ROYALTY_REGISTRY_ADDRESS } from 'utils/constants'
|
||||
import type { AirdropAllocation } from 'utils/isValidAccountsFile'
|
||||
import { resolveAddress } from 'utils/resolveAddress'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import type { CollectionInfo } from '../../../contracts/sg721/contract'
|
||||
import { TextInput } from '../../forms/FormInput'
|
||||
@@ -246,7 +246,7 @@ export const CollectionActions = ({
|
||||
recipient: resolvedRecipientAddress,
|
||||
recipients: airdropArray,
|
||||
tokenRecipients: airdropAllocationArray,
|
||||
txSigner: wallet.address,
|
||||
txSigner: wallet.address || '',
|
||||
type,
|
||||
price: priceState.value.toString(),
|
||||
baseUri: baseURIState.value.trim().endsWith('/')
|
||||
@@ -335,13 +335,15 @@ export const CollectionActions = ({
|
||||
throw new Error('Please enter minter and sg721 contract addresses!')
|
||||
}
|
||||
|
||||
if (wallet.client && type === 'update_mint_price') {
|
||||
const contractConfig = wallet.client.queryContractSmart(minterContractAddress, {
|
||||
if (wallet.isWalletConnected && type === 'update_mint_price') {
|
||||
const contractConfig = (await wallet.getCosmWasmClient()).queryContractSmart(minterContractAddress, {
|
||||
config: {},
|
||||
})
|
||||
await toast
|
||||
.promise(
|
||||
wallet.client.queryContractSmart(minterContractAddress, {
|
||||
(
|
||||
await wallet.getCosmWasmClient()
|
||||
).queryContractSmart(minterContractAddress, {
|
||||
mint_price: {},
|
||||
}),
|
||||
{
|
||||
@@ -373,7 +375,9 @@ export const CollectionActions = ({
|
||||
})
|
||||
} else {
|
||||
await contractConfig.then(async (config) => {
|
||||
const factoryParameters = await wallet.client?.queryContractSmart(config.factory, {
|
||||
const factoryParameters = await (
|
||||
await wallet.getCosmWasmClient()
|
||||
).queryContractSmart(config.factory, {
|
||||
params: {},
|
||||
})
|
||||
if (
|
||||
@@ -403,8 +407,8 @@ export const CollectionActions = ({
|
||||
royaltyPaymentAddressState.value &&
|
||||
!royaltyPaymentAddressState.value.trim().endsWith('.stars')
|
||||
) {
|
||||
const contractInfoResponse = await wallet.client
|
||||
?.queryContractRaw(
|
||||
const contractInfoResponse = await (await wallet.getCosmWasmClient())
|
||||
.queryContractRaw(
|
||||
royaltyPaymentAddressState.value.trim(),
|
||||
toUtf8(Buffer.from(Buffer.from('contract_info').toString('hex'), 'hex').toString()),
|
||||
)
|
||||
|
||||
@@ -8,10 +8,10 @@ import clsx from 'clsx'
|
||||
import { Alert } from 'components/Alert'
|
||||
import { Conditional } from 'components/Conditional'
|
||||
import { useInputState } from 'components/forms/FormInput.hooks'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import React, { useCallback, useEffect, useState } from 'react'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import { API_URL } from 'utils/constants'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { useDebounce } from '../../../utils/debounce'
|
||||
import { TextInput } from '../../forms/FormInput'
|
||||
@@ -56,7 +56,7 @@ export const BaseMinterDetails = ({ onChange, minterType, importedBaseMinterDeta
|
||||
|
||||
const fetchMinterContracts = async (): Promise<MinterInfo[]> => {
|
||||
const contracts: MinterInfo[] = await axios
|
||||
.get(`${API_URL}/api/v1beta/collections/${wallet.address}`)
|
||||
.get(`${API_URL}/api/v1beta/collections/${wallet.address || ''}`)
|
||||
.then((response) => {
|
||||
const collectionData = response.data
|
||||
const minterContracts = collectionData.map((collection: any) => {
|
||||
@@ -70,8 +70,8 @@ export const BaseMinterDetails = ({ onChange, minterType, importedBaseMinterDeta
|
||||
}
|
||||
|
||||
async function getMinterContractType(minterContractAddress: string) {
|
||||
if (wallet.client && minterContractAddress.length > 0) {
|
||||
const client = wallet.client
|
||||
if (wallet.isWalletConnected && minterContractAddress.length > 0) {
|
||||
const client = await wallet.getCosmWasmClient()
|
||||
const data = await client.queryContractRaw(
|
||||
minterContractAddress,
|
||||
toUtf8(Buffer.from(Buffer.from('contract_info').toString('hex'), 'hex').toString()),
|
||||
@@ -129,8 +129,10 @@ export const BaseMinterDetails = ({ onChange, minterType, importedBaseMinterDeta
|
||||
|
||||
const fetchSg721Address = async () => {
|
||||
if (debouncedExistingBaseMinterContract.length === 0) return
|
||||
await wallet.client
|
||||
?.queryContractSmart(debouncedExistingBaseMinterContract, {
|
||||
await (
|
||||
await wallet.getCosmWasmClient()
|
||||
)
|
||||
.queryContractSmart(debouncedExistingBaseMinterContract, {
|
||||
config: {},
|
||||
})
|
||||
.then((response) => {
|
||||
@@ -145,8 +147,10 @@ export const BaseMinterDetails = ({ onChange, minterType, importedBaseMinterDeta
|
||||
|
||||
const fetchCollectionTokenCount = async () => {
|
||||
if (selectedCollectionAddress === undefined) return
|
||||
await wallet.client
|
||||
?.queryContractSmart(selectedCollectionAddress, {
|
||||
await (
|
||||
await wallet.getCosmWasmClient()
|
||||
)
|
||||
.queryContractSmart(selectedCollectionAddress, {
|
||||
num_tokens: {},
|
||||
})
|
||||
.then((response) => {
|
||||
@@ -164,7 +168,7 @@ export const BaseMinterDetails = ({ onChange, minterType, importedBaseMinterDeta
|
||||
setMyBaseMinterContracts([])
|
||||
existingBaseMinterState.onChange('')
|
||||
void displayToast()
|
||||
} else if (baseMinterAcquisitionMethod === 'new' || !wallet.initialized) {
|
||||
} else if (baseMinterAcquisitionMethod === 'new' || !wallet.isWalletConnected) {
|
||||
setMyBaseMinterContracts([])
|
||||
existingBaseMinterState.onChange('')
|
||||
}
|
||||
@@ -194,7 +198,7 @@ export const BaseMinterDetails = ({ onChange, minterType, importedBaseMinterDeta
|
||||
}, [
|
||||
existingBaseMinterState.value,
|
||||
baseMinterAcquisitionMethod,
|
||||
wallet.initialized,
|
||||
wallet.isWalletConnected,
|
||||
selectedCollectionAddress,
|
||||
collectionTokenCount,
|
||||
])
|
||||
@@ -270,7 +274,7 @@ export const BaseMinterDetails = ({ onChange, minterType, importedBaseMinterDeta
|
||||
</Conditional>
|
||||
<Conditional test={myBaseMinterContracts.length === 0}>
|
||||
<div className="flex flex-col">
|
||||
<Conditional test={wallet.initialized}>
|
||||
<Conditional test={wallet.isWalletConnected}>
|
||||
<Alert className="my-2 w-[90%]" type="info">
|
||||
No previous 1/1 collections were found. You may create a new 1/1 collection or fill in the minter
|
||||
contract address manually.
|
||||
@@ -282,7 +286,7 @@ export const BaseMinterDetails = ({ onChange, minterType, importedBaseMinterDeta
|
||||
isRequired
|
||||
/>
|
||||
</Conditional>
|
||||
<Conditional test={!wallet.initialized}>
|
||||
<Conditional test={!wallet.isWalletConnected}>
|
||||
<Alert className="my-2 w-[90%]" type="warning">
|
||||
Please connect your wallet first.
|
||||
</Alert>
|
||||
|
||||
@@ -10,8 +10,8 @@ import { stars, tokensList } from 'config/token'
|
||||
import { useGlobalSettings } from 'contexts/globalSettings'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { resolveAddress } from 'utils/resolveAddress'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { useWallet } from '../../../contexts/wallet'
|
||||
import { NumberInput, TextInput } from '../../forms/FormInput'
|
||||
import type { UploadMethod } from './UploadDetails'
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Conditional } from 'components/Conditional'
|
||||
import { FormGroup } from 'components/FormGroup'
|
||||
import { useInputState } from 'components/forms/FormInput.hooks'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { resolveAddress } from '../../../utils/resolveAddress'
|
||||
import { NumberInput, TextInput } from '../../forms/FormInput'
|
||||
|
||||
@@ -10,9 +10,9 @@ import type { WhitelistFlexMember } from 'components/WhitelistFlexUpload'
|
||||
import { WhitelistFlexUpload } from 'components/WhitelistFlexUpload'
|
||||
import type { TokenInfo } from 'config/token'
|
||||
import { useGlobalSettings } from 'contexts/globalSettings'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { isValidAddress } from 'utils/isValidAddress'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { Conditional } from '../../Conditional'
|
||||
import { AddressInput, NumberInput } from '../../forms/FormInput'
|
||||
|
||||
@@ -12,8 +12,8 @@ import type { SG721Instance } from 'contracts/sg721'
|
||||
import type { VendingMinterInstance } from 'contracts/vendingMinter'
|
||||
import { toast } from 'react-hot-toast'
|
||||
import { useQuery } from 'react-query'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { useWallet } from '../../../contexts/wallet'
|
||||
import { resolveAddress } from '../../../utils/resolveAddress'
|
||||
import type { MinterType } from '../actions/Combobox'
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { toUtf8 } from '@cosmjs/encoding'
|
||||
import { FormControl } from 'components/FormControl'
|
||||
import { AddressInput } from 'components/forms/FormInput'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import { useEffect, useId, useMemo } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { FaMinus, FaPlus } from 'react-icons/fa'
|
||||
import { SG721_NAME_ADDRESS } from 'utils/constants'
|
||||
import { isValidAddress } from 'utils/isValidAddress'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { useInputState } from './FormInput.hooks'
|
||||
|
||||
@@ -66,8 +66,10 @@ export function Address({ id, isLast, onAdd, onChange, onRemove, defaultValue }:
|
||||
})
|
||||
|
||||
const resolveAddress = async (name: string) => {
|
||||
if (!wallet.client) throw new Error('Wallet not connected')
|
||||
await wallet.client
|
||||
if (!wallet.isWalletConnected) throw new Error('Wallet not connected')
|
||||
await (
|
||||
await wallet.getCosmWasmClient()
|
||||
)
|
||||
.queryContractRaw(
|
||||
SG721_NAME_ADDRESS,
|
||||
toUtf8(
|
||||
|
||||
@@ -2,12 +2,12 @@ import { toUtf8 } from '@cosmjs/encoding'
|
||||
import { FormControl } from 'components/FormControl'
|
||||
import { AddressInput, NumberInput } from 'components/forms/FormInput'
|
||||
import type { WhitelistFlexMember } from 'components/WhitelistFlexUpload'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import { useEffect, useId, useMemo } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { FaMinus, FaPlus } from 'react-icons/fa'
|
||||
import { SG721_NAME_ADDRESS } from 'utils/constants'
|
||||
import { isValidAddress } from 'utils/isValidAddress'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { useInputState, useNumberInputState } from './FormInput.hooks'
|
||||
|
||||
@@ -75,8 +75,10 @@ export function FlexMemberAttribute({ id, isLast, onAdd, onChange, onRemove, def
|
||||
}, [addressState.value, mintCountState.value, id])
|
||||
|
||||
const resolveAddress = async (name: string) => {
|
||||
if (!wallet.client) throw new Error('Wallet not connected')
|
||||
await wallet.client
|
||||
if (!wallet.isWalletConnected) throw new Error('Wallet not connected')
|
||||
await (
|
||||
await wallet.getCosmWasmClient()
|
||||
)
|
||||
.queryContractRaw(
|
||||
SG721_NAME_ADDRESS,
|
||||
toUtf8(
|
||||
|
||||
@@ -10,8 +10,8 @@ import { stars, tokensList } from 'config/token'
|
||||
import { useGlobalSettings } from 'contexts/globalSettings'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { resolveAddress } from 'utils/resolveAddress'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { useWallet } from '../../contexts/wallet'
|
||||
import { NumberInput, TextInput } from '../forms/FormInput'
|
||||
import type { UploadMethod } from './OffChainMetadataUploadDetails'
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import clsx from 'clsx'
|
||||
import { Conditional } from 'components/Conditional'
|
||||
import { useInputState } from 'components/forms/FormInput.hooks'
|
||||
import { useMetadataAttributesState } from 'components/forms/MetadataAttributes.hooks'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import type { Trait } from 'contracts/badgeHub'
|
||||
import type { ChangeEvent } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
@@ -40,7 +39,6 @@ export const OnChainMetadataInputDetails = ({
|
||||
uploadMethod,
|
||||
importedOnChainMetadataInputDetails,
|
||||
}: OnChainMetadataInputDetailsProps) => {
|
||||
const wallet = useWallet()
|
||||
const [timestamp, setTimestamp] = useState<Date | undefined>(undefined)
|
||||
const [metadataFile, setMetadataFile] = useState<File>()
|
||||
const [metadataFeeRate, setMetadataFeeRate] = useState<number>(0)
|
||||
|
||||
@@ -16,7 +16,6 @@ import { openEditionMinterList } from 'config/minter'
|
||||
import type { TokenInfo } from 'config/token'
|
||||
import { useContracts } from 'contexts/contracts'
|
||||
import { addLogItem } from 'contexts/log'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import type { DispatchExecuteArgs as OpenEditionFactoryDispatchExecuteArgs } from 'contracts/openEditionFactory/messages/execute'
|
||||
import { dispatchExecute as openEditionFactoryDispatchExecute } from 'contracts/openEditionFactory/messages/execute'
|
||||
import React, { useEffect, useMemo, useState } from 'react'
|
||||
@@ -32,6 +31,7 @@ import type { AssetType } from 'utils/getAssetType'
|
||||
import { isValidAddress } from 'utils/isValidAddress'
|
||||
import { checkTokenUri } from 'utils/isValidTokenUri'
|
||||
import { uid } from 'utils/random'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { type CollectionDetailsDataProps, CollectionDetails } from './CollectionDetails'
|
||||
import type { ImageUploadDetailsDataProps } from './ImageUploadDetails'
|
||||
@@ -180,7 +180,7 @@ export const OpenEditionMinterCreator = ({
|
||||
}
|
||||
|
||||
const checkUploadDetails = async () => {
|
||||
if (!wallet.initialized) throw new Error('Wallet not connected.')
|
||||
if (!wallet.isWalletConnected) throw new Error('Wallet not connected.')
|
||||
if (
|
||||
(metadataStorageMethod === 'off-chain' && !offChainMetadataUploadDetails) ||
|
||||
(metadataStorageMethod === 'on-chain' && !imageUploadDetails)
|
||||
@@ -338,8 +338,8 @@ export const OpenEditionMinterCreator = ({
|
||||
}
|
||||
throw new Error('Invalid royalty payment address')
|
||||
}
|
||||
const contractInfoResponse = await wallet.client
|
||||
?.queryContractRaw(
|
||||
const contractInfoResponse = await (await wallet.getCosmWasmClient())
|
||||
.queryContractRaw(
|
||||
royaltyDetails.paymentAddress.trim(),
|
||||
toUtf8(Buffer.from(Buffer.from('contract_info').toString('hex'), 'hex').toString()),
|
||||
)
|
||||
@@ -359,11 +359,11 @@ export const OpenEditionMinterCreator = ({
|
||||
}
|
||||
|
||||
const checkwalletBalance = async () => {
|
||||
if (!wallet.initialized) throw new Error('Wallet not connected.')
|
||||
if (!wallet.isWalletConnected) throw new Error('Wallet not connected.')
|
||||
const amountNeeded = collectionDetails?.updatable
|
||||
? Number(openEditionMinterUpdatableCreationFee)
|
||||
: Number(openEditionMinterCreationFee)
|
||||
await wallet.client?.getBalance(wallet.address, 'ustars').then((balance) => {
|
||||
await (await wallet.getCosmWasmClient()).getBalance(wallet.address || '', 'ustars').then((balance) => {
|
||||
if (amountNeeded >= Number(balance.amount))
|
||||
throw new Error(
|
||||
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
|
||||
@@ -559,7 +559,7 @@ export const OpenEditionMinterCreator = ({
|
||||
}
|
||||
|
||||
const instantiateOpenEditionMinter = async (uri: string, coverImageUri: string, thumbnailUri?: string) => {
|
||||
if (!wallet.initialized) throw new Error('Wallet not connected')
|
||||
if (!wallet.isWalletConnected) throw new Error('Wallet not connected')
|
||||
if (!openEditionFactoryContract) throw new Error('Contract not found')
|
||||
if (!openEditionMinterContract) throw new Error('Contract not found')
|
||||
|
||||
@@ -626,7 +626,7 @@ export const OpenEditionMinterCreator = ({
|
||||
const payload: OpenEditionFactoryDispatchExecuteArgs = {
|
||||
contract: collectionDetails?.updatable ? updatableFactoryAddressForSelectedDenom : factoryAddressForSelectedDenom,
|
||||
messages: openEditionFactoryMessages,
|
||||
txSigner: wallet.address,
|
||||
txSigner: wallet.address || '',
|
||||
msg,
|
||||
funds: [
|
||||
coin(
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Conditional } from 'components/Conditional'
|
||||
import { FormGroup } from 'components/FormGroup'
|
||||
import { useInputState } from 'components/forms/FormInput.hooks'
|
||||
import { useWallet } from 'contexts/wallet'
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { resolveAddress } from 'utils/resolveAddress'
|
||||
import { useWallet } from 'utils/wallet'
|
||||
|
||||
import { NumberInput, TextInput } from '../forms/FormInput'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user