Skip to content

Commit

Permalink
Update to @solana/web3.js@^2.0.0-preview
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Mar 8, 2024
1 parent 248801a commit 8fda725
Show file tree
Hide file tree
Showing 10 changed files with 3,038 additions and 2,478 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
6 changes: 3 additions & 3 deletions app/address/[address]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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 { Address } from 'web3js-experimental';

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

Expand Down Expand Up @@ -387,7 +387,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 @@ -467,7 +467,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
5 changes: 2 additions & 3 deletions app/providers/accounts/vote-accounts.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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,
Expand All @@ -18,8 +18,7 @@ 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 = {
Expand Down
7 changes: 2 additions & 5 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 @@ -123,10 +123,7 @@ async function updateCluster(dispatch: Dispatch, cluster: Cluster, customUrl: st
try {
// validate url
new URL(customUrl);

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

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 @@ -56,7 +56,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/web3.js@^2.0.0-preview"
},
"devDependencies": {
"@solana/eslint-config-solana": "^1.0.1",
Expand Down
Loading

0 comments on commit 8fda725

Please sign in to comment.