From ce33240b8519a891bf2cf00593efd5cd00088526 Mon Sep 17 00:00:00 2001 From: Jordan Prince Date: Mon, 26 Apr 2021 23:54:36 -0500 Subject: [PATCH] Latest fixes to bidder metadata --- packages/common/src/actions/auction.ts | 2 + packages/metavinci/src/contexts/meta.tsx | 50 ++++++++++++--------- packages/metavinci/src/hooks/useAuction.ts | 1 + packages/metavinci/src/hooks/useAuctions.ts | 13 +++++- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/packages/common/src/actions/auction.ts b/packages/common/src/actions/auction.ts index 6fd108c..9ef6aa5 100644 --- a/packages/common/src/actions/auction.ts +++ b/packages/common/src/actions/auction.ts @@ -109,6 +109,7 @@ export class AuctionData { } } +export const BIDDER_METADATA_LEN = 32 + 32 + 8 + 8 + 1; export class BidderMetadata { // Relationship with the bidder who's metadata this covers. bidderPubkey: PublicKey; @@ -136,6 +137,7 @@ export class BidderMetadata { } } +export const BIDDER_POT_LEN = 32 + 32 + 32; export class BidderPot { /// Points at actual pot that is a token account bidderPot: PublicKey; diff --git a/packages/metavinci/src/contexts/meta.tsx b/packages/metavinci/src/contexts/meta.tsx index 0e7c0dd..a44ebdd 100644 --- a/packages/metavinci/src/contexts/meta.tsx +++ b/packages/metavinci/src/contexts/meta.tsx @@ -24,6 +24,8 @@ import { decodeBidderMetadata, BidderPot, decodeBidderPot, + BIDDER_METADATA_LEN, + BIDDER_POT_LEN, } from '@oyster/common'; import { MintInfo } from '@solana/spl-token'; import { Connection, PublicKey, PublicKeyAndAccount } from '@solana/web3.js'; @@ -126,7 +128,10 @@ export function MetaProvider({ children = null as any }) { } catch { // ignore errors // add type as first byte for easier deserialization - try { + } + + try { + if (a.account.data.length == BIDDER_METADATA_LEN) { const bidderMetadata = await decodeBidderMetadata(a.account.data); const account: ParsedAccount = { @@ -140,28 +145,29 @@ export function MetaProvider({ children = null as any }) { '-' + bidderMetadata.bidderPubkey.toBase58()]: account, })); - } catch { - // ignore errors - // add type as first byte for easier deserialization - try { - const bidderPot = await decodeBidderPot(a.account.data); - - const account: ParsedAccount = { - pubkey: a.pubkey, - account: a.account, - info: bidderPot, - }; - setBidderPotsByAuctionAndBidder(e => ({ - ...e, - [bidderPot.auctionAct.toBase58() + - '-' + - bidderPot.bidderAct.toBase58()]: account, - })); - } catch { - // ignore errors - // add type as first byte for easier deserialization - } } + } catch { + // ignore errors + // add type as first byte for easier deserialization + } + try { + if (a.account.data.length == BIDDER_POT_LEN) { + const bidderPot = await decodeBidderPot(a.account.data); + const account: ParsedAccount = { + pubkey: a.pubkey, + account: a.account, + info: bidderPot, + }; + setBidderPotsByAuctionAndBidder(e => ({ + ...e, + [bidderPot.auctionAct.toBase58() + + '-' + + bidderPot.bidderAct.toBase58()]: account, + })); + } + } catch { + // ignore errors + // add type as first byte for easier deserialization } }; diff --git a/packages/metavinci/src/hooks/useAuction.ts b/packages/metavinci/src/hooks/useAuction.ts index 2619b24..7fc8f90 100644 --- a/packages/metavinci/src/hooks/useAuction.ts +++ b/packages/metavinci/src/hooks/useAuction.ts @@ -30,6 +30,7 @@ export const useAuction = (id: string) => { useEffect(() => { const auction = auctions[id]; if (auction) { + console.log(bidderMetadataByAuctionAndBidder); const auctionView = processAccountsIntoAuctionView( auction, auctionManagers, diff --git a/packages/metavinci/src/hooks/useAuctions.ts b/packages/metavinci/src/hooks/useAuctions.ts index c0078b4..4371efd 100644 --- a/packages/metavinci/src/hooks/useAuctions.ts +++ b/packages/metavinci/src/hooks/useAuctions.ts @@ -66,7 +66,6 @@ export const useAuctions = (state: AuctionViewState) => { } = useMeta(); useEffect(() => { - console.log('Clock', clock); if (clock != 0) Object.keys(auctions).forEach(a => { const auction = auctions[a]; @@ -119,7 +118,6 @@ export function processAccountsIntoAuctionView( existingAuctionView?: AuctionView, ): AuctionView | undefined { let state: AuctionViewState; - console.log(auction?.info?.endedAt?.toNumber(), clock); if ( auction.info.state == AuctionState.Ended || (auction.info.endedAt && auction.info.endedAt.toNumber() <= clock) @@ -152,6 +150,17 @@ export function processAccountsIntoAuctionView( bidderPotsByAuctionAndBidder[ auction.pubkey.toBase58() + '-' + myPayingAccount?.pubkey.toBase58() ]; + if ( + auction.pubkey.toBase58() == + 'CLxhAeuhz8KX3y8yEWHADtmTzE26ofAnd6j8zwMXjW9P' + ) { + console.log( + 'I found', + + bidderMetadata, + myPayingAccount?.pubkey.toBase58(), + ); + } if (existingAuctionView && existingAuctionView.totallyComplete) { // If totally complete, we know we arent updating anythign else, let's speed things up // and only update the two things that could possibly change