Skip to content

Commit

Permalink
[deps] Update MUI and aptos dependencies (#789)
Browse files Browse the repository at this point in the history
* [deps] Update MUI and aptos dependencies

* [util] Remove hexinput from utils

* [constants] Remove randomnet

* [constants] Remove WHILTELISTED testnet delegation nodes

* [wallet-adapter] Fix Network to be SDK v2 instead of V1

* [refactor] Remove all usages of Hex from sdk v1, use account address

* [refactor] remove randomnet
  • Loading branch information
gregnazario authored Sep 30, 2024
1 parent ec41a03 commit 7168c12
Show file tree
Hide file tree
Showing 7 changed files with 557 additions and 406 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
"dependencies": {
"@apollo/client": "^3.8.9",
"@aptos-labs/aptos-names-connector": "^0.0.2",
"@aptos-labs/ts-sdk": "1.22.2",
"@aptos-labs/wallet-adapter-mui-design": "^3.0.1",
"@aptos-labs/wallet-adapter-react": "^3.5.1",
"@aptos-labs/ts-sdk": "1.28.0",
"@aptos-labs/wallet-adapter-mui-design": "^3.0.14",
"@aptos-labs/wallet-adapter-react": "^3.7.0",
"@bitget-wallet/aptos-wallet-adapter": "^0.1.2",
"@blocto/aptos-wallet-adapter-plugin": "^0.2.8",
"@blocto/aptos-wallet-adapter-plugin": "^0.2.10",
"@download/blockies": "^1.0.3",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@martianwallet/aptos-wallet-adapter": "^0.0.5",
"@msafe/aptos-wallet-adapter": "^1.1.3",
"@mui/icons-material": "^5.15.4",
"@mui/material": "^5.15.4",
"@mui/system": "^5.15.4",
"@mui/x-date-pickers": "^7.0.0",
"@mui/icons-material": "^5.15.21",
"@mui/material": "^5.15.21",
"@mui/system": "^5.15.20",
"@mui/x-date-pickers": "^7.18.0",
"@okwallet/aptos-wallet-adapter": "^0.0.7",
"@openblockhq/aptos-wallet-adapter": "^0.1.5",
"@pontem/wallet-adapter-plugin": "^0.2.1",
Expand Down
892 changes: 532 additions & 360 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/api/hooks/useGraphqlClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export function getGraphqlURI(networkName: NetworkName): string | undefined {
return "https://api.devnet.staging.aptoslabs.com/v1/graphql";
case "local":
return "http://127.0.0.1:8090/v1/graphql";
case "randomnet":
return "https://indexer.random.aptoslabs.com/v1/graphql";
default:
return undefined;
}
Expand Down
7 changes: 0 additions & 7 deletions src/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const networks: Record<string, string> = {
devnet: devnetUrl,
local: "http://127.0.0.1:8080/v1",
previewnet: "https://fullnode.previewnet.aptoslabs.com/v1",
randomnet: "https://fullnode.random.aptoslabs.com/v1",
};

export type NetworkName = keyof typeof networks;
Expand All @@ -37,7 +36,6 @@ const apiKeys: ApiKeys = {
devnet: "AG-GA6I9F6H8NM1ACW8ZVJGMPUTJUKZ5KN6A",
local: undefined,
previewnet: undefined,
randomnet: undefined,
};

export function getApiKey(network_name: NetworkName): string | undefined {
Expand All @@ -54,7 +52,6 @@ export enum Network {
DEVNET = "devnet",
LOCAL = "local",
PREVIEWNET = "previewnet",
RANDOMNET = "randomnet",
}

// Remove trailing slashes
Expand Down Expand Up @@ -107,10 +104,6 @@ export const defaultFeature = features[defaultFeatureName];
* Delegation Service
*/
export const OCTA = 100000000;
export const WHILTELISTED_TESTNET_DELEGATION_NODES = import.meta.env
.REACT_APP_WHILTELISTED_TESTNET_DELEGATION_NODES
? import.meta.env.REACT_APP_WHILTELISTED_TESTNET_DELEGATION_NODES.split(",")
: null;

/**
* Core Address
Expand Down
13 changes: 8 additions & 5 deletions src/pages/DelegatoryValidator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import PageHeader from "../layout/PageHeader";
import ValidatorTitle from "./Title";
import ValidatorDetailCard from "./DetailCard";
import ValidatorStakingBar from "./StakingBar";
import {HexString} from "aptos";
import {
useGetValidators,
ValidatorData,
Expand All @@ -21,14 +20,18 @@ import Error from "../Account/Error";
import {useGetDelegationNodeInfo} from "../../api/hooks/useGetDelegationNodeInfo";
import {Banner} from "../../components/Banner";
import {useGetDelegationNodeCommissionChange} from "../../api/hooks/useGetDelegationNodeCommissionChange";
import {AccountAddress} from "@aptos-labs/ts-sdk";

export default function ValidatorPage() {
const address = useParams().address ?? "";
const addressHex = useMemo(() => new HexString(address), [address]);
const addressHex = useMemo(
() => AccountAddress.from(address).toStringLong(),
[address],
);
const {validators} = useGetValidators();
const {connected} = useWallet();
const {data: accountResource, error} = useGetAccountResource(
addressHex.hex(),
addressHex,
"0x1::stake::StakePool",
);
const {
Expand All @@ -43,7 +46,7 @@ export default function ValidatorPage() {
const [delegationValidator, setDelegationValidator] =
useState<ValidatorData>();
const validator = validators.find(
(validator) => validator.owner_address === addressHex.hex(),
(validator) => validator.owner_address === addressHex,
);

const {commission} = useGetDelegationNodeInfo({
Expand All @@ -61,7 +64,7 @@ export default function ValidatorPage() {
const delegatedStakingPoolsNotInValidators: ValidatorData[] =
delegatedStakingPools
.filter((pool) => {
return addressHex.hex() === pool.staking_pool_address;
return addressHex === pool.staking_pool_address;
})
.map((pool) => ({
owner_address: pool.staking_pool_address,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {FewchaWallet} from "fewcha-plugin-wallet-adapter";
import {MSafeWalletAdapter} from "@msafe/aptos-wallet-adapter";
import {OKXWallet} from "@okwallet/aptos-wallet-adapter";
import {useMemo} from "react";
import {Network} from "aptos";
import {Network} from "@aptos-labs/ts-sdk";

const AptosConnectId = "99d260d0-c69d-4c15-965f-f6f9b7b00102";

Expand Down
31 changes: 8 additions & 23 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {AnyAptosWallet} from "@aptos-labs/wallet-adapter-react";
import {HexString, Types} from "aptos";
import {Types} from "aptos";
import pako from "pako";
import {Statsig} from "statsig-react";
import {AccountAddress, Hex} from "@aptos-labs/ts-sdk";
/**
* Helper function for exhaustiveness checks.
*
Expand Down Expand Up @@ -87,16 +88,17 @@ export async function fetchJsonResponse(url: string) {
*/
export function transformCode(source: string): string {
try {
return pako.ungzip(new HexString(source).toUint8Array(), {to: "string"});
return pako.ungzip(Hex.fromHexString(source).toUint8Array(), {
to: "string",
});
} catch {
return "";
}
}

export function getBytecodeSizeInKB(bytecodeHex: string): number {
// Convert the hex string to a byte array
const textEncoder = new TextEncoder();
const byteArray = new Uint8Array(textEncoder.encode(bytecodeHex));
const byteArray = Hex.fromHexString(bytecodeHex).toUint8Array();

// Compute the size of the byte array in kilobytes (KB)
const sizeInKB = byteArray.length / 1024;
Expand All @@ -109,24 +111,7 @@ export function getBytecodeSizeInKB(bytecodeHex: string): number {
* Standardizes an address to the format "0x" followed by 64 lowercase hexadecimal digits.
*/
export const standardizeAddress = (address: string): string => {
// Convert the address to lowercase
address = address.toLowerCase();
// If the address has more than 66 characters, it's already invalid
if (address.length > 66) {
return address;
}
// Remove the "0x" prefix if present
const addressWithoutPrefix = address.startsWith("0x")
? address.slice(2)
: address;
// If the address has more than 64 characters after removing the prefix, it's already invalid
if (addressWithoutPrefix.length > 64) {
return address;
}
// Pad the address with leading zeros if necessary to ensure it has exactly 64 characters (excluding the "0x" prefix)
const addressWithPadding = addressWithoutPrefix.padStart(64, "0");
// Return the standardized address with the "0x" prefix
return "0x" + addressWithPadding;
return AccountAddress.from(address).toStringLong();
};

// inspired by https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
Expand Down Expand Up @@ -196,7 +181,7 @@ function encodeVectorForViewRequest(type: string, value: string) {
if (match) {
if (match[1] === "u8") {
return (
HexString.fromUint8Array(
new Hex(
new Uint8Array(
rawVector.map((v) => {
const result = ensureNumber(v.trim());
Expand Down

0 comments on commit 7168c12

Please sign in to comment.