Still need to fix bid numbers but looking good and added load all metadata button.
This commit is contained in:
parent
5ad9cf556f
commit
4b21878c22
|
@ -65,6 +65,26 @@ const WHITELISTED_AUCTION_MANAGER = [
|
|||
];
|
||||
const WHITELISTED_VAULT = ['3wHCBd3fYRPWjd5GqzrXanLJUKRyU3nECKbTPKfVwcFX'];
|
||||
|
||||
export const pullStoreMetadata = async (
|
||||
connection: Connection,
|
||||
tempCache: MetaState,
|
||||
) => {
|
||||
const updateTemp = makeSetter(tempCache);
|
||||
|
||||
const loadMetadata = () =>
|
||||
pullMetadataByCreators(connection, tempCache, updateTemp);
|
||||
const loadEditions = () => pullEditions(connection, updateTemp, tempCache);
|
||||
|
||||
console.log('-------->Loading all metadata for store.');
|
||||
|
||||
await loadMetadata();
|
||||
await loadEditions();
|
||||
|
||||
await postProcessMetadata(tempCache);
|
||||
console.log('-------->Metadata processing complete.');
|
||||
return tempCache;
|
||||
};
|
||||
|
||||
export const pullYourMetadata = async (
|
||||
connection: Connection,
|
||||
userTokenAccounts: TokenAccount[],
|
||||
|
|
|
@ -12,7 +12,7 @@ import { MetaContextState, MetaState } from './types';
|
|||
import { useConnection } from '../connection';
|
||||
import { useStore } from '../store';
|
||||
import { AuctionData, BidderMetadata, BidderPot } from '../../actions';
|
||||
import { pullAuctionSubaccounts, pullPage } from '.';
|
||||
import { pullAuctionSubaccounts, pullPage, pullStoreMetadata } from '.';
|
||||
import { StringPublicKey, TokenAccount, useUserAccounts } from '../..';
|
||||
|
||||
const MetaContext = React.createContext<MetaContextState>({
|
||||
|
@ -52,6 +52,23 @@ export function MetaProvider({ children = null as any }) {
|
|||
},
|
||||
[setState],
|
||||
);
|
||||
async function pullAllMetadata() {
|
||||
if (isLoading) return false;
|
||||
if (!storeAddress) {
|
||||
if (isReady) {
|
||||
setIsLoading(false);
|
||||
}
|
||||
return;
|
||||
} else if (!state.store) {
|
||||
setIsLoading(true);
|
||||
}
|
||||
setIsLoading(true);
|
||||
const nextState = await pullStoreMetadata(connection, state);
|
||||
setIsLoading(false);
|
||||
setState(nextState);
|
||||
await updateMints(nextState.metadataByMint);
|
||||
return [];
|
||||
}
|
||||
|
||||
async function pullAuctionPage(auctionAddress: StringPublicKey) {
|
||||
if (isLoading) return false;
|
||||
|
@ -103,14 +120,25 @@ export function MetaProvider({ children = null as any }) {
|
|||
} else {
|
||||
console.log('------->Pagination detected, pulling page', page);
|
||||
|
||||
if (userTokenAccounts && userTokenAccounts.length && !metadataLoaded) {
|
||||
// Ensures we get the latest so beat race conditions and avoid double pulls.
|
||||
let currMetadataLoaded = false;
|
||||
setMetadataLoaded(loaded => {
|
||||
currMetadataLoaded = loaded;
|
||||
return loaded;
|
||||
});
|
||||
if (
|
||||
userTokenAccounts &&
|
||||
userTokenAccounts.length &&
|
||||
!currMetadataLoaded
|
||||
) {
|
||||
console.log('--------->User metadata loading now.');
|
||||
|
||||
setMetadataLoaded(true);
|
||||
nextState = await pullYourMetadata(
|
||||
connection,
|
||||
userTokenAccounts,
|
||||
nextState,
|
||||
);
|
||||
setMetadataLoaded(true);
|
||||
}
|
||||
const auction = window.location.href.match(/#\/auction\/(\w+)/);
|
||||
if (auction && page == 0) {
|
||||
|
@ -177,7 +205,7 @@ export function MetaProvider({ children = null as any }) {
|
|||
}
|
||||
|
||||
return subscribeAccountsChange(connection, () => state, setState);
|
||||
}, [connection, setState, isLoading]);
|
||||
}, [connection, setState, isLoading, state]);
|
||||
|
||||
// TODO: fetch names dynamically
|
||||
// TODO: get names for creators
|
||||
|
@ -214,6 +242,7 @@ export function MetaProvider({ children = null as any }) {
|
|||
// @ts-ignore
|
||||
update,
|
||||
pullAuctionPage,
|
||||
pullAllMetadata,
|
||||
isLoading,
|
||||
}}
|
||||
>
|
||||
|
|
|
@ -93,7 +93,7 @@ export interface MetaContextState extends MetaState {
|
|||
];
|
||||
pullAuctionPage: (auctionAddress: StringPublicKey) => void;
|
||||
|
||||
pullUserMetadata: (tokenAccounts: TokenAccount[]) => void;
|
||||
pullAllMetadata: () => void;
|
||||
}
|
||||
|
||||
export type AccountAndPubkey = {
|
||||
|
|
|
@ -22,7 +22,7 @@ export const ArtworksView = () => {
|
|||
const { connected, publicKey } = useWallet();
|
||||
const ownedMetadata = useUserArts();
|
||||
const createdMetadata = useCreatorArts(publicKey?.toBase58() || '');
|
||||
const { metadata, isLoading } = useMeta();
|
||||
const { metadata, isLoading, pullAllMetadata, storeIndexer } = useMeta();
|
||||
const [activeKey, setActiveKey] = useState(ArtworkViewState.Metaplex);
|
||||
const breakpointColumnsObj = {
|
||||
default: 4,
|
||||
|
@ -103,6 +103,9 @@ export const ArtworksView = () => {
|
|||
</TabPane>
|
||||
)}
|
||||
</Tabs>
|
||||
{connected && storeIndexer.length && (
|
||||
<a onClick={() => pullAllMetadata()}>Load all metadata</a>
|
||||
)}
|
||||
</Row>
|
||||
</Col>
|
||||
</Content>
|
||||
|
|
Loading…
Reference in New Issue