From 3b34e2de4e777f5b09fd42c3555b87ac746d7913 Mon Sep 17 00:00:00 2001 From: John Rees Date: Sun, 6 Jun 2021 11:03:29 +0100 Subject: [PATCH 1/5] replace occurrences of !==/== with !==/=== https://eslint.org/docs/2.0.0/rules/eqeqeq --- js/packages/web/src/actions/addTokensToVault.ts | 2 +- js/packages/web/src/actions/cancelBid.ts | 2 +- js/packages/web/src/actions/createAuctionManager.ts | 2 +- .../src/actions/createReservationListsForTokens.ts | 2 +- .../web/src/actions/populatePrintingTokens.ts | 2 +- js/packages/web/src/actions/sendRedeemBid.ts | 12 ++++++------ js/packages/web/src/actions/settle.ts | 12 ++++++------ js/packages/web/src/components/MeshViewer/utils.js | 9 ++++----- js/packages/web/src/contexts/meta.tsx | 2 +- 9 files changed, 22 insertions(+), 23 deletions(-) diff --git a/js/packages/web/src/actions/addTokensToVault.ts b/js/packages/web/src/actions/addTokensToVault.ts index 1b63fff..3dc0300 100644 --- a/js/packages/web/src/actions/addTokensToVault.ts +++ b/js/packages/web/src/actions/addTokensToVault.ts @@ -103,7 +103,7 @@ export async function addTokensToVault( } } - if (instructions[instructions.length - 1] != currInstructions) { + if (instructions[instructions.length - 1] !== currInstructions) { signers.push(currSigners); instructions.push(currInstructions); } diff --git a/js/packages/web/src/actions/cancelBid.ts b/js/packages/web/src/actions/cancelBid.ts index f438a83..74894f6 100644 --- a/js/packages/web/src/actions/cancelBid.ts +++ b/js/packages/web/src/actions/cancelBid.ts @@ -29,7 +29,7 @@ export async function sendCancelBid( let instructions: Array = []; if ( auctionView.auction.info.ended() && - auctionView.auction.info.state != AuctionState.Ended + auctionView.auction.info.state !== AuctionState.Ended ) { await setupPlaceBid( connection, diff --git a/js/packages/web/src/actions/createAuctionManager.ts b/js/packages/web/src/actions/createAuctionManager.ts index 555c3c3..b5852f9 100644 --- a/js/packages/web/src/actions/createAuctionManager.ts +++ b/js/packages/web/src/actions/createAuctionManager.ts @@ -308,7 +308,7 @@ export async function createAuctionManager( instructions = instructions.slice(stopPoint, instructions.length); filteredSigners = filteredSigners.slice(stopPoint, filteredSigners.length); - if (instructions.length == lastInstructionsLength) tries = tries + 1; + if (instructions.length === lastInstructionsLength) tries = tries + 1; else tries = 0; try { diff --git a/js/packages/web/src/actions/createReservationListsForTokens.ts b/js/packages/web/src/actions/createReservationListsForTokens.ts index 16dba62..1f93518 100644 --- a/js/packages/web/src/actions/createReservationListsForTokens.ts +++ b/js/packages/web/src/actions/createReservationListsForTokens.ts @@ -52,7 +52,7 @@ export async function createReservationListForTokens( batchCounter++; } - if (instructions[instructions.length - 1] != currInstructions) { + if (instructions[instructions.length - 1] !== currInstructions) { signers.push(currSigners); instructions.push(currInstructions); } diff --git a/js/packages/web/src/actions/populatePrintingTokens.ts b/js/packages/web/src/actions/populatePrintingTokens.ts index 480a51f..51820c0 100644 --- a/js/packages/web/src/actions/populatePrintingTokens.ts +++ b/js/packages/web/src/actions/populatePrintingTokens.ts @@ -102,7 +102,7 @@ export async function populatePrintingTokens( } } - if (instructions[instructions.length - 1] != currInstructions) { + if (instructions[instructions.length - 1] !== currInstructions) { signers.push(currSigners); instructions.push(currInstructions); } diff --git a/js/packages/web/src/actions/sendRedeemBid.ts b/js/packages/web/src/actions/sendRedeemBid.ts index ae15ae0..3ec5dc7 100644 --- a/js/packages/web/src/actions/sendRedeemBid.ts +++ b/js/packages/web/src/actions/sendRedeemBid.ts @@ -69,7 +69,7 @@ export async function sendRedeemBid( if ( auctionView.auction.info.ended() && - auctionView.auction.info.state != AuctionState.Ended + auctionView.auction.info.state !== AuctionState.Ended ) { await setupPlaceBid( connection, @@ -112,7 +112,7 @@ export async function sendRedeemBid( const winningConfigItem = winningConfig.items[j]; if ( - winningConfigItem.safetyDepositBoxIndex == safetyDeposit.info.order + winningConfigItem.safetyDepositBoxIndex === safetyDeposit.info.order ) { const stateItem = auctionView.auctionManager.info.state.winningConfigStates[ @@ -232,7 +232,7 @@ export async function sendRedeemBid( instructions = instructions.slice(stopPoint, instructions.length); filteredSigners = filteredSigners.slice(stopPoint, filteredSigners.length); - if (instructions.length == lastInstructionsLength) tries = tries + 1; + if (instructions.length === lastInstructionsLength) tries = tries + 1; else tries = 0; try { @@ -575,8 +575,8 @@ async function setupRedeemParticipationInstructions( ); if ( - participationBalance.value.uiAmount == 0 && - tokenBalance.value.uiAmount == 1 + participationBalance.value.uiAmount === 0 && + tokenBalance.value.uiAmount === 1 ) { // I'm the first, I need to populate for the others with a crank turn. let fillParticipationStashSigners: Keypair[] = []; @@ -694,7 +694,7 @@ async function setupRedeemParticipationInstructions( } } - if (newTokenAccount && newTokenBalance == 1) { + if (newTokenAccount && newTokenBalance === 1) { await redeemPrintingToken( wallet, updateAuth, diff --git a/js/packages/web/src/actions/settle.ts b/js/packages/web/src/actions/settle.ts index f69266c..513d15c 100644 --- a/js/packages/web/src/actions/settle.ts +++ b/js/packages/web/src/actions/settle.ts @@ -117,11 +117,11 @@ async function emptyPaymentAccountForAllTokens( auctionView.auction.pubkey, wallet.publicKey, addresses[k], - item == auctionView.participationItem ? null : i, - item == auctionView.participationItem ? null : j, + item === auctionView.participationItem ? null : i, + item === auctionView.participationItem ? null : j, creatorIndex === -1 || creatorIndex === null || - (edgeCaseWhereCreatorIsAuctioneer && k == addresses.length - 1) + (edgeCaseWhereCreatorIsAuctioneer && k === addresses.length - 1) ? null : creatorIndex, settleInstructions, @@ -134,7 +134,7 @@ async function emptyPaymentAccountForAllTokens( settleInstructions = []; } - if (currInstrBatch.length == BATCH_SIZE) { + if (currInstrBatch.length === BATCH_SIZE) { signers.push(currSignerBatch); instructions.push(currInstrBatch); currSignerBatch = []; @@ -213,14 +213,14 @@ async function claimAllBids( claimBidInstructions, ); - if (claimBidInstructions.length == CLAIM_TRANSACTION_SIZE) { + if (claimBidInstructions.length === CLAIM_TRANSACTION_SIZE) { currSignerBatch.push(claimBidSigners); currInstrBatch.push(claimBidInstructions); claimBidSigners = []; claimBidInstructions = []; } - if (currInstrBatch.length == BATCH_SIZE) { + if (currInstrBatch.length === BATCH_SIZE) { signers.push(currSignerBatch); instructions.push(currInstrBatch); currSignerBatch = []; diff --git a/js/packages/web/src/components/MeshViewer/utils.js b/js/packages/web/src/components/MeshViewer/utils.js index dd00947..eb13809 100644 --- a/js/packages/web/src/components/MeshViewer/utils.js +++ b/js/packages/web/src/components/MeshViewer/utils.js @@ -15,7 +15,6 @@ import { // Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish // Pan - right mouse, or left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move - const TouchableOrbitControls = function (object, domElement) { if (domElement === undefined) console.warn( @@ -574,7 +573,7 @@ const TouchableOrbitControls = function (object, domElement) { } function handleTouchStartRotate(event) { - if (event.touches.length == 1) { + if (event.touches.length === 1) { rotateStart.set(event.touches[0].pageX, event.touches[0].pageY); } else { const x = 0.5 * (event.touches[0].pageX + event.touches[1].pageX); @@ -585,7 +584,7 @@ const TouchableOrbitControls = function (object, domElement) { } function handleTouchStartPan(event) { - if (event.touches.length == 1) { + if (event.touches.length === 1) { panStart.set(event.touches[0].pageX, event.touches[0].pageY); } else { const x = 0.5 * (event.touches[0].pageX + event.touches[1].pageX); @@ -617,7 +616,7 @@ const TouchableOrbitControls = function (object, domElement) { } function handleTouchMoveRotate(event) { - if (event.touches.length == 1) { + if (event.touches.length === 1) { rotateEnd.set(event.touches[0].pageX, event.touches[0].pageY); } else { const x = 0.5 * (event.touches[0].pageX + event.touches[1].pageX); @@ -640,7 +639,7 @@ const TouchableOrbitControls = function (object, domElement) { } function handleTouchMovePan(event) { - if (event.touches.length == 1) { + if (event.touches.length === 1) { panEnd.set(event.touches[0].pageX, event.touches[0].pageY); } else { const x = 0.5 * (event.touches[0].pageX + event.touches[1].pageX); diff --git a/js/packages/web/src/contexts/meta.tsx b/js/packages/web/src/contexts/meta.tsx index 3dc1fec..e50df9e 100644 --- a/js/packages/web/src/contexts/meta.tsx +++ b/js/packages/web/src/contexts/meta.tsx @@ -697,7 +697,7 @@ const processMetaplexAccounts = async ( whitelistedCreator.address, ); if ( - creatorKeyIfCreatorWasPartOfThisStore.toBase58() == a.pubkey.toBase58() + creatorKeyIfCreatorWasPartOfThisStore.toBase58() === a.pubkey.toBase58() ) { const account = cache.add( a.pubkey, From 0eb3a74951d3a5067551b6d99107b71c210f2922 Mon Sep 17 00:00:00 2001 From: John Rees Date: Sun, 6 Jun 2021 11:04:09 +0100 Subject: [PATCH 2/5] use colons in interface --- js/packages/web/src/components/AmountLabel/index.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/packages/web/src/components/AmountLabel/index.tsx b/js/packages/web/src/components/AmountLabel/index.tsx index 7c96be0..ddcef9f 100644 --- a/js/packages/web/src/components/AmountLabel/index.tsx +++ b/js/packages/web/src/components/AmountLabel/index.tsx @@ -5,11 +5,11 @@ import { formatUSD } from '@oyster/common' import './index.less'; interface IAmountLabel { - amount: number | string, - displayUSD?: boolean, - title?: string, - style?: object, - containerStyle?: object, + amount: number | string; + displayUSD?: boolean; + title?: string; + style?: object; + containerStyle?: object; } export const AmountLabel = (props: IAmountLabel) => { From 710253660e00aa4003d37b2eefa37699d3fb284e Mon Sep 17 00:00:00 2001 From: John Rees Date: Sun, 6 Jun 2021 11:06:16 +0100 Subject: [PATCH 3/5] remove some unused code in views/artist(s) --- js/packages/web/src/views/artist/index.tsx | 9 +++------ js/packages/web/src/views/artists/index.tsx | 11 +++-------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/js/packages/web/src/views/artist/index.tsx b/js/packages/web/src/views/artist/index.tsx index 59ea650..76fb21e 100644 --- a/js/packages/web/src/views/artist/index.tsx +++ b/js/packages/web/src/views/artist/index.tsx @@ -1,13 +1,10 @@ +import { Col, Divider, Row } from 'antd'; import React from 'react'; -import { Row, Col, Divider, Layout, Tag, Badge } from 'antd'; -import { useParams } from 'react-router-dom'; -import { useCreator } from '../../hooks'; import Masonry from 'react-masonry-css'; +import { Link, useParams } from 'react-router-dom'; import { ArtCard } from '../../components/ArtCard'; -import { useCreatorArts } from '../../hooks'; -import { Link } from 'react-router-dom'; import { CardLoader } from '../../components/MyLoader'; -import { MetaAvatar } from '../../components/MetaAvatar'; +import { useCreator, useCreatorArts } from '../../hooks'; export const ArtistView = () => { const { id } = useParams<{ id: string }>(); diff --git a/js/packages/web/src/views/artists/index.tsx b/js/packages/web/src/views/artists/index.tsx index e8fbc04..8b46057 100644 --- a/js/packages/web/src/views/artists/index.tsx +++ b/js/packages/web/src/views/artists/index.tsx @@ -1,18 +1,13 @@ -import React, { useState } from 'react'; -import { ArtCard } from '../../components/ArtCard'; -import { Layout, Row, Col, Tabs } from 'antd'; +import { Col, Layout } from 'antd'; +import React from 'react'; import Masonry from 'react-masonry-css'; import { Link } from 'react-router-dom'; -import { useUserArts } from '../../hooks'; -import { useMeta } from '../../contexts'; import { ArtistCard } from '../../components/ArtistCard'; - -const { TabPane } = Tabs; +import { useMeta } from '../../contexts'; const { Content } = Layout; export const ArtistsView = () => { - const ownedMetadata = useUserArts(); const { whitelistedCreatorsByCreator } = useMeta(); const breakpointColumnsObj = { default: 4, From 9c0bf5fc7bb227e472b96aeed87669f1ba5593d0 Mon Sep 17 00:00:00 2001 From: Jordan Prince Date: Mon, 7 Jun 2021 11:33:16 -0400 Subject: [PATCH 4/5] Prep for switch of ids --- js/packages/common/src/actions/metadata.ts | 3 +- js/packages/common/src/actions/vault.ts | 3 +- js/packages/web/src/contexts/meta.tsx | 58 ++++++++++++-------- js/packages/web/src/models/metaplex/index.ts | 4 +- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/js/packages/common/src/actions/metadata.ts b/js/packages/common/src/actions/metadata.ts index 24a4667..ef3a8c1 100644 --- a/js/packages/common/src/actions/metadata.ts +++ b/js/packages/common/src/actions/metadata.ts @@ -36,7 +36,8 @@ export const MAX_METADATA_LEN = export const MAX_MASTER_EDITION_KEN = 1 + 9 + 8 + 32 + 32; export enum MetadataKey { - MetadataV1 = 0, + Uninitialized = 0, + MetadataV1 = 4, EditionV1 = 1, MasterEditionV1 = 2, ReservationListV1 = 3, diff --git a/js/packages/common/src/actions/vault.ts b/js/packages/common/src/actions/vault.ts index 814e1f2..005e5ed 100644 --- a/js/packages/common/src/actions/vault.ts +++ b/js/packages/common/src/actions/vault.ts @@ -10,7 +10,8 @@ import BN from 'bn.js'; export const VAULT_PREFIX = 'vault'; export enum VaultKey { - VaultV1 = 0, + Uninitialized = 0, + VaultV1 = 3, SafetyDepositBoxV1 = 1, ExternalPriceAccountV1 = 2, } diff --git a/js/packages/web/src/contexts/meta.tsx b/js/packages/web/src/contexts/meta.tsx index 3dc1fec..3fa3e77 100644 --- a/js/packages/web/src/contexts/meta.tsx +++ b/js/packages/web/src/contexts/meta.tsx @@ -29,13 +29,15 @@ import { useConnectionConfig, } from '@oyster/common'; import { MintInfo } from '@solana/spl-token'; -import { - Connection, - PublicKey, - PublicKeyAndAccount -} from '@solana/web3.js'; +import { Connection, PublicKey, PublicKeyAndAccount } from '@solana/web3.js'; import BN from 'bn.js'; -import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react'; +import React, { + useCallback, + useContext, + useEffect, + useMemo, + useState, +} from 'react'; import { AuctionManager, AuctionManagerStatus, @@ -165,18 +167,18 @@ export function MetaProvider({ children = null as any }) { setSafetyDepositBoxesByVaultAndIndex, ] = useState>>({}); - const updateMints = useCallback(async (metadataByMint) => { - try { - const m = await queryExtendedMetadata( - connection, - metadataByMint, - ); - setMetadata(m.metadata); - setMetadataByMint(m.mintToMetadata); - } catch (er) { - console.error(er); - } - }, [setMetadata, setMetadataByMint]); + const updateMints = useCallback( + async metadataByMint => { + try { + const m = await queryExtendedMetadata(connection, metadataByMint); + setMetadata(m.metadata); + setMetadataByMint(m.mintToMetadata); + } catch (er) { + console.error(er); + } + }, + [setMetadata, setMetadataByMint], + ); useEffect(() => { let dispose = () => {}; @@ -435,7 +437,7 @@ export function MetaProvider({ children = null as any }) { setPayoutTickets, setStore, setWhitelistedCreatorsByCreator, - updateMints + updateMints, ]); const filteredMetadata = useMemo( @@ -639,8 +641,12 @@ const processMetaplexAccounts = async ( setWhitelistedCreatorsByCreator: any, ) => { try { - const STORE_ID = programIds().store.toBase58() - if (a.account.data[0] === MetaplexKey.AuctionManagerV1) { + const STORE_ID = programIds().store.toBase58(); + + if ( + a.account.data[0] === MetaplexKey.AuctionManagerV1 || + a.account.data[0] === 0 + ) { const storeKey = new PublicKey(a.account.data.slice(1, 33)); if (storeKey.toBase58() === STORE_ID) { const auctionManager = decodeAuctionManager(a.account.data); @@ -735,7 +741,10 @@ const processMetaData = async ( setMasterEditionsByOneTimeAuthMint: any, ) => { try { - if (meta.account.data[0] === MetadataKey.MetadataV1) { + if ( + meta.account.data[0] === MetadataKey.MetadataV1 || + meta.account.data[0] === 0 + ) { const metadata = await decodeMetadata(meta.account.data); if ( @@ -807,7 +816,10 @@ const processVaultData = ( ...e, [safetyDeposit.vault.toBase58() + '-' + safetyDeposit.order]: account, })); - } else if (a.account.data[0] === VaultKey.VaultV1) { + } else if ( + a.account.data[0] === VaultKey.VaultV1 || + a.account.data[0] === 0 + ) { const vault = decodeVault(a.account.data); const account: ParsedAccount = { pubkey: a.pubkey, diff --git a/js/packages/web/src/models/metaplex/index.ts b/js/packages/web/src/models/metaplex/index.ts index d7b4de3..82a5f3a 100644 --- a/js/packages/web/src/models/metaplex/index.ts +++ b/js/packages/web/src/models/metaplex/index.ts @@ -19,12 +19,14 @@ export const METAPLEX_PREFIX = 'metaplex'; export const ORIGINAL_AUTHORITY_LOOKUP_SIZE = 33; export enum MetaplexKey { - AuctionManagerV1 = 0, + Uninitialized = 0, OriginalAuthorityLookupV1 = 1, BidRedemptionTicketV1 = 2, StoreV1 = 3, WhitelistedCreatorV1 = 4, PayoutTicketV1 = 5, + SafetyDepositValidationTicketV1 = 6, + AuctionManagerV1 = 7, } export class PayoutTicket { From 8e5dcf56eabb6d9e16d2ce4d1900641c709b0727 Mon Sep 17 00:00:00 2001 From: Jordan Prince Date: Mon, 7 Jun 2021 15:30:21 -0400 Subject: [PATCH 5/5] Fix tiny b ug in data layer where accounts from one program get parsed as messed up versions of accounts from another program because key enum matches --- js/packages/web/src/contexts/meta.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/packages/web/src/contexts/meta.tsx b/js/packages/web/src/contexts/meta.tsx index 3fa3e77..766a1fd 100644 --- a/js/packages/web/src/contexts/meta.tsx +++ b/js/packages/web/src/contexts/meta.tsx @@ -578,6 +578,8 @@ const processAuctions = ( setBidderMetadataByAuctionAndBidder: any, setBidderPotsByAuctionAndBidder: any, ) => { + if (a.account.owner.toBase58() != programIds().auction.toBase58()) return; + try { const account = cache.add( a.pubkey, @@ -640,6 +642,8 @@ const processMetaplexAccounts = async ( setStore: any, setWhitelistedCreatorsByCreator: any, ) => { + if (a.account.owner.toBase58() != programIds().metaplex.toBase58()) return; + try { const STORE_ID = programIds().store.toBase58(); @@ -740,6 +744,8 @@ const processMetaData = async ( setmasterEditionsByPrintingMint: any, setMasterEditionsByOneTimeAuthMint: any, ) => { + if (meta.account.owner.toBase58() != programIds().metadata.toBase58()) return; + try { if ( meta.account.data[0] === MetadataKey.MetadataV1 || @@ -804,6 +810,7 @@ const processVaultData = ( setSafetyDepositBoxesByVaultAndIndex: any, setVaults: any, ) => { + if (a.account.owner.toBase58() != programIds().vault.toBase58()) return; try { if (a.account.data[0] === VaultKey.SafetyDepositBoxV1) { const safetyDeposit = decodeSafetyDeposit(a.account.data);