Skip to content

Commit

Permalink
Eliminate PublicKey from isAddressLookupTableAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Oct 18, 2023
1 parent 6b33f2a commit acc2d75
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/address/[address]/entries/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { LookupTableEntriesCard } from '@components/account/address-lookup-table
import { isAddressLookupTableAccount } from '@components/account/address-lookup-table/types';
import { ParsedAccountRenderer } from '@components/account/ParsedAccountRenderer';
import React from 'react';
import { Base58EncodedAddress } from 'web3js-experimental';

type Props = Readonly<{
params: {
Expand All @@ -19,7 +20,7 @@ function AddressLookupTableEntriesRenderer({
const rawData = account?.data.raw;
if (parsedData && parsedData.program === 'address-lookup-table' && parsedData.parsed.type === 'lookupTable') {
return <LookupTableEntriesCard parsedLookupTable={parsedData.parsed.info} />;
} else if (rawData && isAddressLookupTableAccount(account.owner, rawData)) {
} else if (rawData && isAddressLookupTableAccount(account.owner.toBase58() as Base58EncodedAddress, rawData)) {
return <LookupTableEntriesCard lookupTableAccountData={rawData} />;
} else {
return onNotFound();
Expand Down
5 changes: 3 additions & 2 deletions app/address/[address]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import Link from 'next/link';
import { redirect, useSelectedLayoutSegment } from 'next/navigation';
import React, { PropsWithChildren } from 'react';
import useSWRImmutable from 'swr/immutable';
import { Base58EncodedAddress } from 'web3js-experimental';

import { FullTokenInfo, getFullTokenInfo } from '@/app/utils/token-info';

Expand Down Expand Up @@ -361,7 +362,7 @@ function InfoSection({ account, tokenInfo }: { account: Account, tokenInfo?: Ful
parsedData.parsed.type === 'lookupTable'
) {
return <AddressLookupTableAccountSection account={account} lookupTableAccount={parsedData.parsed.info} />;
} else if (rawData && isAddressLookupTableAccount(account.owner, rawData)) {
} else if (rawData && isAddressLookupTableAccount(account.owner.toBase58() as Base58EncodedAddress, rawData)) {
return <AddressLookupTableAccountSection account={account} data={rawData} />;
} else if (account.owner.toBase58() === FEATURE_PROGRAM_ID) {
return <FeatureAccountSection account={account} />;
Expand Down Expand Up @@ -441,7 +442,7 @@ function getTabs(pubkey: PublicKey, account: Account): TabComponent[] {
}

// Add the key for address lookup tables
if (account.data.raw && isAddressLookupTableAccount(account.owner, account.data.raw)) {
if (account.data.raw && isAddressLookupTableAccount(account.owner.toBase58() as Base58EncodedAddress, account.data.raw)) {
tabs.push(...TABS_LOOKUP['address-lookup-table']);
}

Expand Down
11 changes: 6 additions & 5 deletions app/components/account/address-lookup-table/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { PublicKey } from '@solana/web3.js';
import { Base58EncodedAddress } from 'web3js-experimental';

const PROGRAM_ID = 'AddressLookupTab1e1111111111111111111111111';
const LOOKUP_TABLE_ACCOUNT_TYPE = 1;
const PROGRAM_ID =
'AddressLookupTab1e1111111111111111111111111' as Base58EncodedAddress<'AddressLookupTab1e1111111111111111111111111'>;

export function isAddressLookupTableAccount(accountOwner: PublicKey, accountData: Uint8Array): boolean {
if (accountOwner.toBase58() !== PROGRAM_ID) return false;
export function isAddressLookupTableAccount(accountOwner: Base58EncodedAddress, accountData: Uint8Array): boolean {
if (accountOwner !== PROGRAM_ID) return false;
if (!accountData || accountData.length === 0) return false;
const LOOKUP_TABLE_ACCOUNT_TYPE = 1;
return accountData[0] === LOOKUP_TABLE_ACCOUNT_TYPE;
}

0 comments on commit acc2d75

Please sign in to comment.