Skip to content

Commit

Permalink
get asset list on sell nft click
Browse files Browse the repository at this point in the history
  • Loading branch information
iskysun96 committed May 31, 2024
1 parent 43e2fcd commit 699f752
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
1 change: 0 additions & 1 deletion projects/orakle-nft-marketplace-app-frontend/src/atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export const algorandClientAtom = atom<AlgorandClient | null>(null)
export const listClientAtom = atom<NftMarketplaceListClient | null>(null)
export const isSellingAtom = atom<boolean>(false)
export const appDetailsListAtom = atom<appDetails[]>([])
export const assetHoldingAtom = atom<bigint[]>([])
export const healthAtom = atom<boolean>(false)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useWallet } from '@txnlab/use-wallet'
import { useAtomValue } from 'jotai'
import { useState } from 'react'
import { isSellingAtom } from '../atoms'
import { algorandClientAtom, isSellingAtom } from '../atoms'
import { ellipseAddress } from '../utils/ellipseAddress'
import ConnectWallet from './ConnectWallet'
import MintNft from './MintNft'
Expand All @@ -11,16 +11,27 @@ import Withdraw from './Withdraw'
export function Header() {
const { activeAddress } = useWallet()
const isSelling = useAtomValue(isSellingAtom)
const algorandClient = useAtomValue(algorandClientAtom)

const [openWalletModal, setOpenWalletModal] = useState(false)
const [openSellModal, setOpenSellModal] = useState(false)
const [openWithdrawModal, setOpenWithdrawModal] = useState(false)
const [openMintModal, setOpenMintModal] = useState(false)
const [assetHolding, setAssetHolding] = useState<bigint[]>([])

const toggleWalletModal = () => {
setOpenWalletModal((prev) => !prev)
}
const toggleSellModal = () => {
if (activeAddress && algorandClient) {
algorandClient!.account.getInformation(activeAddress!).then((info) => {
const listOfAssetsHolding = []
for (const asset of info.assets!) {
listOfAssetsHolding.push(BigInt(asset.assetId))
}
setAssetHolding(listOfAssetsHolding)
})
}
setOpenSellModal((prev) => !prev)
}
const toggleWithdrawModal = () => {
Expand Down Expand Up @@ -51,7 +62,7 @@ export function Header() {
</button>
</div>
<ConnectWallet openModal={openWalletModal} closeModal={toggleWalletModal} />
<Sell openModal={openSellModal} setModalState={setOpenSellModal} />
<Sell assetHolding={assetHolding} openModal={openSellModal} setModalState={setOpenSellModal} />
<Withdraw openModal={openWithdrawModal} setModalState={setOpenWithdrawModal} />
<MintNft openModal={openMintModal} setModalState={setOpenMintModal} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import { useWallet } from '@txnlab/use-wallet'
import { useAtomValue } from 'jotai'
import { useSnackbar } from 'notistack'
import { useState } from 'react'
import { algorandClientAtom, assetHoldingAtom, listClientAtom } from '../atoms'
import { algorandClientAtom, listClientAtom } from '../atoms'
import * as methods from '../methods'
import { getCurrentNftmClient } from '../utils/getCurrentNftmClient'

interface SellInterface {
assetHolding: bigint[]
openModal: boolean
setModalState: (value: boolean) => void
}

const Sell = ({ openModal, setModalState }: SellInterface) => {
const Sell = ({ assetHolding, openModal, setModalState }: SellInterface) => {
const [loading, setLoading] = useState<boolean>(false)
const [assetIdToSell, setAssetIdToSell] = useState<string>('')
const [unitaryPrice, setUnitaryPrice] = useState<string>('')
Expand All @@ -22,7 +23,6 @@ const Sell = ({ openModal, setModalState }: SellInterface) => {
const { signer, activeAddress, clients, activeAccount } = useWallet()
const algorandClient = useAtomValue(algorandClientAtom)
const listClient = useAtomValue(listClientAtom)
const assetHolding = useAtomValue(assetHoldingAtom)

const handleMethodCall = async () => {
setLoading(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AlgorandClient from '@algorandfoundation/algokit-utils/types/algorand-cli
import { useWallet } from '@txnlab/use-wallet'
import { useAtom, useSetAtom } from 'jotai'
import { useEffect, useState } from 'react'
import { algorandClientAtom, appDetailsListAtom, assetHoldingAtom, healthAtom, isSellingAtom, listClientAtom } from '../atoms'
import { algorandClientAtom, appDetailsListAtom, healthAtom, isSellingAtom, listClientAtom } from '../atoms'
import { NftMarketplaceListClient } from '../contracts/NftMarketplaceList'
import { getAppList } from '../utils/getAppList'
import { marketplaceListAppId } from '../utils/marketplaceListAppId'
Expand All @@ -16,7 +16,6 @@ export function useMarketPlace() {
const [listClient, setListClient] = useAtom(listClientAtom)
const setAppDetailsList = useSetAtom(appDetailsListAtom)
const setIsSelling = useSetAtom(isSellingAtom)
const setAssetHolding = useSetAtom(assetHoldingAtom)
const setHealthAtom = useSetAtom(healthAtom)
const [health, setHealth] = useState(false)

Expand Down Expand Up @@ -71,14 +70,6 @@ export function useMarketPlace() {
const isUserSelling = appList.some((app) => app.creator === activeAddress)
setIsSelling(isUserSelling)
setHealthAtom(true)

algorandClient.account.getInformation(activeAddress).then((info) => {
const listOfAssetsHolding = []
for (const asset of info.assets!) {
listOfAssetsHolding.push(BigInt(asset.assetId))
}
setAssetHolding(listOfAssetsHolding)
})
})
}
}, [algorandClient, listClient, activeAddress])
Expand Down

0 comments on commit 699f752

Please sign in to comment.