implement update auctionview without refresh, fix claimBid instruction

This commit is contained in:
Maxim Gordienko 2021-09-03 18:41:11 +03:00
parent 3c7a9d2ae3
commit d9d87407ee
5 changed files with 41 additions and 22 deletions

View File

@ -129,8 +129,8 @@ export async function sendRedeemBid(
winnerIndex = auctionView.auction.info.bidState.getWinnerIndex(
auctionView.myBidderPot?.info.bidderAct,
);
console.log('Winner index', winnerIndex);
/**@ToDo need to fix hardcoded winner index for instant sale*/
winnerIndex = 0;
if (winnerIndex !== null) {
// items is a prebuilt array of arrays where each entry represents one
// winning spot, and each entry in it represents one type of item that can

View File

@ -25,7 +25,7 @@ import {
import { useWallet } from '@solana/wallet-adapter-react';
import { AuctionView, useBidsForAuction, useUserBalance } from '../../hooks';
import { sendPlaceBid } from '../../actions/sendPlaceBid';
import { bidAndClaimInstantSale } from '../../actions/bidAndClaimInstantSale';
// import { bidAndClaimInstantSale } from '../../actions/bidAndClaimInstantSale';
import { AuctionNumbers } from './../AuctionNumbers';
import {
sendRedeemBid,
@ -184,6 +184,7 @@ export const AuctionCard = ({
action?: JSX.Element;
}) => {
const connection = useConnection();
const {update} = useMeta();
const wallet = useWallet();
const { setVisible } = useWalletModal();
@ -517,10 +518,11 @@ export const AuctionCard = ({
);
setLastBid(bid);
// TODO: Remove this by propating necessary information to sendRedeemBid
window.location.reload();
return;
// window.location.reload();
}
await update();
setShowBidModal(false);
// Claim the purchase

View File

@ -52,6 +52,7 @@ const MetaContext = React.createContext<MetaContextState>({
payoutTickets: {},
prizeTrackingTickets: {},
stores: {},
update: () => {},
});
export function MetaProvider({ children = null as any }) {
@ -108,30 +109,33 @@ export function MetaProvider({ children = null as any }) {
[setState],
);
useEffect(() => {
(async () => {
if (!storeAddress) {
if (isReady) {
setIsLoading(false);
}
return;
} else if (!state.store) {
setIsLoading(true);
async function update () {
if (!storeAddress) {
if (isReady) {
setIsLoading(false);
}
return;
} else if (!state.store) {
setIsLoading(true);
}
console.log('-----> Query started');
console.log('-----> Query started');
const nextState = await loadAccounts(connection, all);
const nextState = await loadAccounts(connection, all);
console.log('loadAccounts',nextState)
console.log('------->Query finished');
console.log('------->Query finished');
setState(nextState);
setState(nextState);
setIsLoading(false);
console.log('------->set finished');
setIsLoading(false);
console.log('------->set finished');
updateMints(nextState.metadataByMint);
}
updateMints(nextState.metadataByMint);
})();
useEffect(() => {
update();
}, [connection, setState, updateMints, storeAddress, isReady]);
const updateStateValue = useMemo<UpdateStateValueFunc>(
@ -228,6 +232,7 @@ export function MetaProvider({ children = null as any }) {
value={{
...state,
isLoading,
update
}}
>
{children}

View File

@ -76,6 +76,7 @@ export interface MetaState {
export interface MetaContextState extends MetaState {
isLoading: boolean;
update: () => void;
}
export type AccountAndPubkey = {

View File

@ -1,4 +1,5 @@
import {
getAuctionExtended,
getBidderPotKey,
programIds,
StringPublicKey,
@ -34,6 +35,11 @@ export async function claimBid(
const value = new ClaimBidArgs();
const data = Buffer.from(serialize(SCHEMA, value));
const auctionExtendedKey = await getAuctionExtended({
auctionProgramId: PROGRAM_IDS.auction,
resource: vault,
});
const keys = [
{
pubkey: toPublicKey(acceptPayment),
@ -61,6 +67,11 @@ export async function claimBid(
isSigner: false,
isWritable: false,
},
{
pubkey: toPublicKey(auctionExtendedKey),
isSigner: false,
isWritable: false,
},
{
pubkey: toPublicKey(bidder),
isSigner: false,