Skip to content

Commit

Permalink
Upgrade @solana/web3.js to 2.0.0-rc.0 (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher authored Aug 2, 2024
1 parent 00f541a commit 1ac3288
Show file tree
Hide file tree
Showing 10 changed files with 483 additions and 142 deletions.
4 changes: 2 additions & 2 deletions app/address/[address]/entries/page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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';
import { Address } from 'web3js-experimental';

type Props = Readonly<{
params: {
Expand All @@ -20,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.toBase58() as Base58EncodedAddress, rawData)) {
} else if (rawData && isAddressLookupTableAccount(account.owner.toBase58() as Address, rawData)) {
return <LookupTableEntriesCard lookupTableAccountData={rawData} />;
} else {
return onNotFound();
Expand Down
9 changes: 3 additions & 6 deletions app/address/[address]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import React, { PropsWithChildren, Suspense } from 'react';
import { ErrorBoundary } from 'react-error-boundary';
import { create } from 'superstruct';
import useSWRImmutable from 'swr/immutable';
import { Base58EncodedAddress } from 'web3js-experimental';
import { Address } from 'web3js-experimental';

import { CompressedNftAccountHeader, CompressedNftCard } from '@/app/components/account/CompressedNftCard';
import { useCompressedNft } from '@/app/providers/compressed-nft';
Expand Down Expand Up @@ -441,7 +441,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.toBase58() as Base58EncodedAddress, rawData)) {
} else if (rawData && isAddressLookupTableAccount(account.owner.toBase58() as Address, rawData)) {
return <AddressLookupTableAccountSection account={account} data={rawData} />;
} else if (account.owner.toBase58() === FEATURE_PROGRAM_ID) {
return <FeatureAccountSection account={account} />;
Expand Down Expand Up @@ -529,10 +529,7 @@ function getTabs(pubkey: PublicKey, account: Account): TabComponent[] {
}

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

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

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

export function isAddressLookupTableAccount(accountOwner: Base58EncodedAddress, accountData: Uint8Array): boolean {
export function isAddressLookupTableAccount(accountOwner: Address, accountData: Uint8Array): boolean {
if (accountOwner !== PROGRAM_ID) return false;
if (!accountData || accountData.length === 0) return false;
return accountData[0] === LOOKUP_TABLE_ACCOUNT_TYPE;
Expand Down
13 changes: 6 additions & 7 deletions app/providers/accounts/vote-accounts.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { useCluster } from '@providers/cluster';
import { Cluster } from '@utils/cluster';
import React from 'react';
import { createDefaultRpcTransport, createSolanaRpc } from 'web3js-experimental';
import { createSolanaRpc } from 'web3js-experimental';

type VoteAccountInfo = Readonly<{
activatedStake: bigint,
activatedStake: bigint;
}>;

type VoteAccounts = Readonly<{
current: VoteAccountInfo[],
delinquent: VoteAccountInfo[],
current: VoteAccountInfo[];
delinquent: VoteAccountInfo[];
}>;

async function fetchVoteAccounts(
Expand All @@ -18,14 +18,13 @@ async function fetchVoteAccounts(
setVoteAccounts: React.Dispatch<React.SetStateAction<VoteAccounts | undefined>>
) {
try {
const transport = createDefaultRpcTransport({ url });
const rpc = createSolanaRpc({ transport });
const rpc = createSolanaRpc(url);

const voteAccountsResponse = await rpc.getVoteAccounts({ commitment: 'confirmed' }).send();
const voteAccounts: VoteAccounts = {
current: voteAccountsResponse.current.map(c => ({ activatedStake: c.activatedStake })),
delinquent: voteAccountsResponse.delinquent.map(d => ({ activatedStake: d.activatedStake })),
}
};

setVoteAccounts(voteAccounts);
} catch (error) {
Expand Down
5 changes: 2 additions & 3 deletions app/providers/cluster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Cluster, clusterName, ClusterStatus, clusterUrl, DEFAULT_CLUSTER } from
import { localStorageIsAvailable } from '@utils/local-storage';
import { ReadonlyURLSearchParams, usePathname, useRouter, useSearchParams } from 'next/navigation';
import React, { createContext, useContext, useEffect, useReducer, useState } from 'react';
import { createDefaultRpcTransport, createSolanaRpc } from 'web3js-experimental';
import { createSolanaRpc } from 'web3js-experimental';

import { EpochSchedule } from '../utils/epoch-schedule';

Expand Down Expand Up @@ -125,8 +125,7 @@ async function updateCluster(dispatch: Dispatch, cluster: Cluster, customUrl: st
new URL(customUrl);

const transportUrl = clusterUrl(cluster, customUrl);
const transport = createDefaultRpcTransport({ url: transportUrl });
const rpc = createSolanaRpc({ transport });
const rpc = createSolanaRpc(transportUrl);

const [firstAvailableBlock, epochSchedule, epochInfo] = await Promise.all([
rpc.getFirstAvailableBlock().send(),
Expand Down
5 changes: 2 additions & 3 deletions app/providers/stats/solanaClusterStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCluster } from '@providers/cluster';
import { Cluster } from '@utils/cluster';
import React from 'react';
import useTabVisibility from 'use-tab-visibility';
import { createDefaultRpcTransport, createSolanaRpc } from 'web3js-experimental';
import { createSolanaRpc } from 'web3js-experimental';

import { DashboardInfo, DashboardInfoActionType, dashboardInfoReducer, EpochInfo } from './solanaDashboardInfo';
import { PerformanceInfo, PerformanceInfoActionType, performanceInfoReducer, PerformanceSample } from './solanaPerformanceInfo';
Expand Down Expand Up @@ -76,8 +76,7 @@ export function SolanaClusterStatsProvider({ children }: Props) {
React.useEffect(() => {
if (!active || !isTabVisible || !url) return;

const transport = createDefaultRpcTransport({ url });
const rpc = createSolanaRpc({ transport });
const rpc = createSolanaRpc(url);

let lastSlot: bigint | null = null;
let stale = false;
Expand Down
5 changes: 2 additions & 3 deletions app/providers/supply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { useCluster } from '@providers/cluster';
import { Cluster, ClusterStatus } from '@utils/cluster';
import React from 'react';
import { createDefaultRpcTransport, createSolanaRpc } from 'web3js-experimental';
import { createSolanaRpc } from 'web3js-experimental';

export enum Status {
Idle,
Expand Down Expand Up @@ -48,8 +48,7 @@ async function fetch(dispatch: Dispatch, cluster: Cluster, url: string) {
dispatch(Status.Connecting);

try {
const transport = createDefaultRpcTransport({ url });
const rpc = createSolanaRpc({ transport });
const rpc = createSolanaRpc(url);

const supplyResponse = await rpc
.getSupply({ commitment: 'finalized', excludeNonCirculatingAccountsList: true })
Expand Down
4 changes: 2 additions & 2 deletions app/utils/token-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
* So to avoid pulling in extra dependencies we just use the public API directly for search
*/

import { Base58EncodedAddress } from 'web3js-experimental';
import { Address } from 'web3js-experimental';

import { Cluster } from './cluster';

type TokenSearchApiResponseToken = {
address: Base58EncodedAddress;
address: Address;
chainId: number;
name: string;
symbol: string;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"typescript": "5.0.4",
"use-async-effect": "^2.2.7",
"use-tab-visibility": "^1.0.9",
"web3js-experimental": "npm:@solana/[email protected]experimental.7adc22b"
"web3js-experimental": "npm:@solana/[email protected]rc.0"
},
"devDependencies": {
"@solana/eslint-config-solana": "^1.0.1",
Expand Down
Loading

0 comments on commit 1ac3288

Please sign in to comment.