diff --git a/kyasshu b/kyasshu index 26d3ceda9..8c68392f2 160000 --- a/kyasshu +++ b/kyasshu @@ -1 +1 @@ -Subproject commit 26d3ceda9f6d039f552a81155ed3e3b8a4486408 +Subproject commit 8c68392f2d241a6beb0f42f3c755b73c3d780d44 diff --git a/nft-marketplace b/nft-marketplace index 88956558d..b99137582 160000 --- a/nft-marketplace +++ b/nft-marketplace @@ -1 +1 @@ -Subproject commit 88956558d8c655723280f7e10c9480e68e2d88de +Subproject commit b99137582ee7b03ab7af0c1f86ecec07b7beb019 diff --git a/src/App.tsx b/src/App.tsx index 35cb9d274..01d997466 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -32,7 +32,10 @@ const App = () => { path="/:collectionId/nft/:id" element={} /> - } /> + } + /> } diff --git a/src/hooks/use-assets-to-withdraw.ts b/src/hooks/use-assets-to-withdraw.ts index a7d8d137e..ac85dbda6 100644 --- a/src/hooks/use-assets-to-withdraw.ts +++ b/src/hooks/use-assets-to-withdraw.ts @@ -1,5 +1,6 @@ import { useEffect } from 'react'; import { useSelector } from 'react-redux'; +import { useMatch } from 'react-router-dom'; import { useAppDispatch, RootState, @@ -11,6 +12,9 @@ export const useAssetsToWithdraw = () => { const dispatch = useAppDispatch(); const { isConnected, principalId: plugPrincipal } = usePlugStore(); + const match = useMatch('/:collectionId'); + const collectionId = match?.params?.collectionId; + const recentlyFailedTransactions = useSelector( (state: RootState) => state.marketplace.recentlyFailedTransactions, @@ -21,11 +25,10 @@ export const useAssetsToWithdraw = () => { ); useEffect(() => { - if (!isConnected || !plugPrincipal) return; - + if (!isConnected || !plugPrincipal || !collectionId) return; dispatch( marketplaceActions.getAssetsToWithdraw({ - userPrincipalId: plugPrincipal, + collectionId, }), ); }, [ @@ -34,5 +37,7 @@ export const useAssetsToWithdraw = () => { plugPrincipal, recentlyWithdrawnAssets, recentlyFailedTransactions, + collectionId, ]); }; + diff --git a/src/store/features/marketplace/async-thunks/get-assets-to-withdraw.ts b/src/store/features/marketplace/async-thunks/get-assets-to-withdraw.ts index b31c9ffa6..7fe834b53 100644 --- a/src/store/features/marketplace/async-thunks/get-assets-to-withdraw.ts +++ b/src/store/features/marketplace/async-thunks/get-assets-to-withdraw.ts @@ -1,40 +1,51 @@ -import { Principal } from '@dfinity/principal'; import { createAsyncThunk } from '@reduxjs/toolkit'; -import { actorInstanceHandler } from '../../../../integrations/actor'; import { marketplaceSlice } from '../marketplace-slice'; import { AppLog } from '../../../../utils/log'; import { parseBalanceResponse } from '../../../../utils/parser'; import { settingsActions } from '../../settings'; +import { jellyJsInstanceHandler } from '../../../../integrations/jelly-js'; +import { getJellyCollection } from '../../../../utils/jelly'; +import { getPrincipal } from '../../../../integrations/plug'; export type GetAssetsToWithdrawProps = { - userPrincipalId: string; + collectionId: string; }; export const getAssetsToWithdraw = createAsyncThunk< any | undefined, GetAssetsToWithdrawProps >('marketplace/balanceOf', async (params, thunkAPI) => { - // Checks if an actor instance exists already - // otherwise creates a new instance - const actorInstance = await actorInstanceHandler({ + const { collectionId } = params; + + const jellyInstance = await jellyJsInstanceHandler({ thunkAPI, - serviceName: 'marketplace', + collectionId, slice: marketplaceSlice, }); - const { userPrincipalId } = params; - try { - const userPrincipalAddress = Principal.fromText(userPrincipalId); + const collection = await getJellyCollection({ + jellyInstance, + collectionId, + }); + + if (!collection) + throw Error(`Oops! collection ${collectionId} not found!`); - const balanceResponse = await actorInstance.balanceOf( - userPrincipalAddress, + const jellyCollection = await jellyInstance.getJellyCollection( + collection, ); + const assetsToWithdrawResponse = + await jellyCollection.getAssetsToWithdraw({ + user: await getPrincipal(), + }); + const assetsToWithdraw = - !Array.isArray(balanceResponse) || !balanceResponse.length + !Array.isArray(assetsToWithdrawResponse) || + !assetsToWithdrawResponse.length ? [] - : parseBalanceResponse(balanceResponse); + : parseBalanceResponse(assetsToWithdrawResponse); if (!assetsToWithdraw.length) return; @@ -45,3 +56,4 @@ export const getAssetsToWithdraw = createAsyncThunk< AppLog.error(err); } }); +