Skip to content

Commit 699f752

Browse files
committed
get asset list on sell nft click
1 parent 43e2fcd commit 699f752

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

projects/orakle-nft-marketplace-app-frontend/src/atoms.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ export const algorandClientAtom = atom<AlgorandClient | null>(null)
77
export const listClientAtom = atom<NftMarketplaceListClient | null>(null)
88
export const isSellingAtom = atom<boolean>(false)
99
export const appDetailsListAtom = atom<appDetails[]>([])
10-
export const assetHoldingAtom = atom<bigint[]>([])
1110
export const healthAtom = atom<boolean>(false)

projects/orakle-nft-marketplace-app-frontend/src/components/Header.tsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useWallet } from '@txnlab/use-wallet'
22
import { useAtomValue } from 'jotai'
33
import { useState } from 'react'
4-
import { isSellingAtom } from '../atoms'
4+
import { algorandClientAtom, isSellingAtom } from '../atoms'
55
import { ellipseAddress } from '../utils/ellipseAddress'
66
import ConnectWallet from './ConnectWallet'
77
import MintNft from './MintNft'
@@ -11,16 +11,27 @@ import Withdraw from './Withdraw'
1111
export function Header() {
1212
const { activeAddress } = useWallet()
1313
const isSelling = useAtomValue(isSellingAtom)
14+
const algorandClient = useAtomValue(algorandClientAtom)
1415

1516
const [openWalletModal, setOpenWalletModal] = useState(false)
1617
const [openSellModal, setOpenSellModal] = useState(false)
1718
const [openWithdrawModal, setOpenWithdrawModal] = useState(false)
1819
const [openMintModal, setOpenMintModal] = useState(false)
20+
const [assetHolding, setAssetHolding] = useState<bigint[]>([])
1921

2022
const toggleWalletModal = () => {
2123
setOpenWalletModal((prev) => !prev)
2224
}
2325
const toggleSellModal = () => {
26+
if (activeAddress && algorandClient) {
27+
algorandClient!.account.getInformation(activeAddress!).then((info) => {
28+
const listOfAssetsHolding = []
29+
for (const asset of info.assets!) {
30+
listOfAssetsHolding.push(BigInt(asset.assetId))
31+
}
32+
setAssetHolding(listOfAssetsHolding)
33+
})
34+
}
2435
setOpenSellModal((prev) => !prev)
2536
}
2637
const toggleWithdrawModal = () => {
@@ -51,7 +62,7 @@ export function Header() {
5162
</button>
5263
</div>
5364
<ConnectWallet openModal={openWalletModal} closeModal={toggleWalletModal} />
54-
<Sell openModal={openSellModal} setModalState={setOpenSellModal} />
65+
<Sell assetHolding={assetHolding} openModal={openSellModal} setModalState={setOpenSellModal} />
5566
<Withdraw openModal={openWithdrawModal} setModalState={setOpenWithdrawModal} />
5667
<MintNft openModal={openMintModal} setModalState={setOpenMintModal} />
5768
</div>

projects/orakle-nft-marketplace-app-frontend/src/components/Sell.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import { useWallet } from '@txnlab/use-wallet'
22
import { useAtomValue } from 'jotai'
33
import { useSnackbar } from 'notistack'
44
import { useState } from 'react'
5-
import { algorandClientAtom, assetHoldingAtom, listClientAtom } from '../atoms'
5+
import { algorandClientAtom, listClientAtom } from '../atoms'
66
import * as methods from '../methods'
77
import { getCurrentNftmClient } from '../utils/getCurrentNftmClient'
88

99
interface SellInterface {
10+
assetHolding: bigint[]
1011
openModal: boolean
1112
setModalState: (value: boolean) => void
1213
}
1314

14-
const Sell = ({ openModal, setModalState }: SellInterface) => {
15+
const Sell = ({ assetHolding, openModal, setModalState }: SellInterface) => {
1516
const [loading, setLoading] = useState<boolean>(false)
1617
const [assetIdToSell, setAssetIdToSell] = useState<string>('')
1718
const [unitaryPrice, setUnitaryPrice] = useState<string>('')
@@ -22,7 +23,6 @@ const Sell = ({ openModal, setModalState }: SellInterface) => {
2223
const { signer, activeAddress, clients, activeAccount } = useWallet()
2324
const algorandClient = useAtomValue(algorandClientAtom)
2425
const listClient = useAtomValue(listClientAtom)
25-
const assetHolding = useAtomValue(assetHoldingAtom)
2626

2727
const handleMethodCall = async () => {
2828
setLoading(true)

projects/orakle-nft-marketplace-app-frontend/src/hooks/useMarketPlace.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import AlgorandClient from '@algorandfoundation/algokit-utils/types/algorand-cli
22
import { useWallet } from '@txnlab/use-wallet'
33
import { useAtom, useSetAtom } from 'jotai'
44
import { useEffect, useState } from 'react'
5-
import { algorandClientAtom, appDetailsListAtom, assetHoldingAtom, healthAtom, isSellingAtom, listClientAtom } from '../atoms'
5+
import { algorandClientAtom, appDetailsListAtom, healthAtom, isSellingAtom, listClientAtom } from '../atoms'
66
import { NftMarketplaceListClient } from '../contracts/NftMarketplaceList'
77
import { getAppList } from '../utils/getAppList'
88
import { marketplaceListAppId } from '../utils/marketplaceListAppId'
@@ -16,7 +16,6 @@ export function useMarketPlace() {
1616
const [listClient, setListClient] = useAtom(listClientAtom)
1717
const setAppDetailsList = useSetAtom(appDetailsListAtom)
1818
const setIsSelling = useSetAtom(isSellingAtom)
19-
const setAssetHolding = useSetAtom(assetHoldingAtom)
2019
const setHealthAtom = useSetAtom(healthAtom)
2120
const [health, setHealth] = useState(false)
2221

@@ -71,14 +70,6 @@ export function useMarketPlace() {
7170
const isUserSelling = appList.some((app) => app.creator === activeAddress)
7271
setIsSelling(isUserSelling)
7372
setHealthAtom(true)
74-
75-
algorandClient.account.getInformation(activeAddress).then((info) => {
76-
const listOfAssetsHolding = []
77-
for (const asset of info.assets!) {
78-
listOfAssetsHolding.push(BigInt(asset.assetId))
79-
}
80-
setAssetHolding(listOfAssetsHolding)
81-
})
8273
})
8374
}
8475
}, [algorandClient, listClient, activeAddress])

0 commit comments

Comments
 (0)