Skip to content

Commit

Permalink
remove use of deprecated getters from all apps (MystenLabs#13166)
Browse files Browse the repository at this point in the history
## Description 

Describe the changes or additions included in this PR.

## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
hayes-mysten authored Jul 28, 2023
1 parent 7ed6245 commit b96dfa8
Show file tree
Hide file tree
Showing 135 changed files with 384 additions and 388 deletions.
4 changes: 3 additions & 1 deletion apps/core/src/hooks/useFormatCoin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { Coin, CoinMetadata, SUI_TYPE_ARG } from '@mysten/sui.js';
import { Coin } from '@mysten/sui.js';
import { CoinMetadata } from '@mysten/sui.js/client';
import { SUI_TYPE_ARG } from '@mysten/sui.js/utils';
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
import BigNumber from 'bignumber.js';
import { useMemo } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useGetKioskContents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { KIOSK_ITEM, KioskData, KioskItem, fetchKiosk, getOwnedKiosks } from '@m
import { useQuery } from '@tanstack/react-query';
import { useRpcClient } from '../api/RpcClientContext';
import { ORIGINBYTE_KIOSK_OWNER_TOKEN, getKioskIdFromOwnerCap } from '../utils/kiosk';
import { SuiClient } from '@mysten/sui.js/src/client';
import { SuiClient } from '@mysten/sui.js/client';

export type KioskContents = Omit<KioskData, 'items'> & {
items: Partial<KioskItem & SuiObjectResponse>[];
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useGetOwnedObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { useRpcClient } from '../api/RpcClientContext';
import { type SuiObjectDataFilter } from '@mysten/sui.js';
import { type SuiObjectDataFilter } from '@mysten/sui.js/client';
import { useInfiniteQuery } from '@tanstack/react-query';

const MAX_OBJECTS_PER_REQ = 6;
Expand Down
13 changes: 5 additions & 8 deletions apps/core/src/hooks/useGetTransferAmount.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import {
SUI_TYPE_ARG,
SuiTransactionBlockResponse,
getTotalGasUsed,
getTransactionSender,
} from '@mysten/sui.js';
import { SUI_TYPE_ARG } from '@mysten/sui.js/utils';
import { SuiTransactionBlockResponse } from '@mysten/sui.js/client';
import { useMemo } from 'react';
import { getTotalGasUsed } from '../utils/transaction';

export function useGetTransferAmount(txnData: SuiTransactionBlockResponse) {
const { balanceChanges } = txnData;
const sender = getTransactionSender(txnData);
const gas = getTotalGasUsed(txnData);
const sender = txnData.transaction?.data.sender;
const gas = txnData.effects && getTotalGasUsed(txnData.effects);
const changes = useMemo(
() =>
balanceChanges
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/hooks/useGetValidatorsEvents.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { useRpcClient } from '../api/RpcClientContext';
import { type EventId, VALIDATORS_EVENTS_QUERY, SuiEvent } from '@mysten/sui.js';
import { type EventId, SuiEvent } from '@mysten/sui.js/client';
import { useQuery } from '@tanstack/react-query';

type GetValidatorsEvent = {
Expand All @@ -12,6 +11,7 @@ type GetValidatorsEvent = {

// NOTE: This copys the query limit from our Rust JSON RPC backend, this needs to be kept in sync!
const QUERY_MAX_RESULT_LIMIT = 50;
const VALIDATORS_EVENTS_QUERY = '0x3::validator_set::ValidatorEpochInfoEventV2';

//TODO: get validatorEvents by validator address
export function useGetValidatorsEvents({ limit, order }: GetValidatorsEvent) {
Expand Down
11 changes: 4 additions & 7 deletions apps/core/src/hooks/useTransactionSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import {
DryRunTransactionBlockResponse,
type SuiTransactionBlockResponse,
getExecutionStatusType,
getTransactionDigest,
getTransactionSender,
} from '@mysten/sui.js';
} from '@mysten/sui.js/client';
import { useMemo } from 'react';

import { getBalanceChangeSummary } from '../utils/transaction/getBalanceChangeSummary';
Expand Down Expand Up @@ -56,12 +53,12 @@ export function useTransactionSummary({
// Non-dry-run transaction:
return {
gas,
sender: getTransactionSender(transaction),
sender: transaction.transaction?.data.sender,
balanceChanges: balanceChangeSummary,
digest: getTransactionDigest(transaction),
digest: transaction.digest,
label: getLabel(transaction, currentAddress),
objectSummary,
status: getExecutionStatusType(transaction),
status: transaction.effects?.status.status,
timestamp: transaction.timestampMs,
};
} else {
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/utils/hasDisplayData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { SuiObjectResponse, getObjectDisplay } from '@mysten/sui.js';
import { SuiObjectResponse } from '@mysten/sui.js/client';

export const hasDisplayData = (obj: SuiObjectResponse) => !!getObjectDisplay(obj).data;
export const hasDisplayData = (obj: SuiObjectResponse) => !!obj.data?.display?.data;
14 changes: 4 additions & 10 deletions apps/core/src/utils/kiosk.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import {
SuiObjectData,
SuiObjectResponse,
getSuiObjectData,
isSuiObjectResponse,
getObjectFields,
} from '@mysten/sui.js';
import { SuiObjectData, SuiObjectResponse } from '@mysten/sui.js/client';
import { KIOSK_OWNER_CAP } from '@mysten/kiosk';

export const ORIGINBYTE_KIOSK_MODULE =
Expand All @@ -17,12 +11,12 @@ export const ORIGINBYTE_KIOSK_OWNER_TOKEN = `${ORIGINBYTE_KIOSK_MODULE}::OwnerTo

export function isKioskOwnerToken(object?: SuiObjectResponse | SuiObjectData) {
if (!object) return false;
const objectData = isSuiObjectResponse(object) ? getSuiObjectData(object) : object;
const objectData = 'data' in object && object.data ? object.data : (object as SuiObjectData);
return [KIOSK_OWNER_CAP, ORIGINBYTE_KIOSK_OWNER_TOKEN].includes(objectData?.type ?? '');
}

export function getKioskIdFromOwnerCap(object: SuiObjectResponse | SuiObjectData) {
const objectData = isSuiObjectResponse(object) ? getSuiObjectData(object) : object;
const fields = getObjectFields(objectData!);
const objectData = 'data' in object && object.data ? object.data : (object as SuiObjectData);
const fields = objectData.content?.dataType === 'moveObject' ? objectData.content.fields : null;
return fields?.for ?? fields?.kiosk;
}
13 changes: 11 additions & 2 deletions apps/core/src/utils/transaction/getGasSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
DryRunTransactionBlockResponse,
GasCostSummary,
SuiTransactionBlockResponse,
getTotalGasUsed,
SuiGasData,
} from '@mysten/sui.js';
TransactionEffects,
} from '@mysten/sui.js/client';

type Optional<T> = {
[K in keyof T]?: T[K];
Expand Down Expand Up @@ -49,3 +49,12 @@ export function getGasSummary(
gasUsed: transaction?.effects!.gasUsed,
};
}

export function getTotalGasUsed(effects: TransactionEffects): bigint | undefined {
const gasSummary = effects?.gasUsed;
return gasSummary
? BigInt(gasSummary.computationCost) +
BigInt(gasSummary.storageCost) -
BigInt(gasSummary.storageRebate)
: undefined;
}
4 changes: 2 additions & 2 deletions apps/core/src/utils/transaction/getLabel.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { SuiTransactionBlockResponse, getTransactionSender } from '@mysten/sui.js';
import { SuiTransactionBlockResponse } from '@mysten/sui.js/client';

// todo: add more logic for deriving transaction label
export const getLabel = (transaction: SuiTransactionBlockResponse, currentAddress?: string) => {
const isSender = getTransactionSender(transaction) === currentAddress;
const isSender = transaction.transaction?.data.sender === currentAddress;
// Rename to "Send" to Transaction
return isSender ? 'Transaction' : 'Receive';
};
2 changes: 1 addition & 1 deletion apps/core/src/utils/transaction/getOwnerType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { SuiObjectChange } from '@mysten/sui.js';
import type { SuiObjectChange } from '@mysten/sui.js/client';

export const getOwnerType = (change: SuiObjectChange) => {
if (!('owner' in change)) return '';
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/src/components/Activity/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { type EpochPage } from '@mysten/sui.js';
import { type EpochPage } from '@mysten/sui.js/client';
import { Text } from '@mysten/ui';

import { SuiAmount } from '../Table/SuiAmount';
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/src/components/GasBreakdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useFormatCoin,
useResolveSuiNSName,
} from '@mysten/core';
import { SUI_TYPE_ARG } from '@mysten/sui.js';
import { SUI_TYPE_ARG } from '@mysten/sui.js/utils';
import { Heading, Text } from '@mysten/ui';

import { CopyToClipboard } from '~/ui/CopyToClipboard';
Expand Down
9 changes: 6 additions & 3 deletions apps/explorer/src/components/Object/ObjectFieldsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import { useGetObject, useGetNormalizedMoveStruct } from '@mysten/core';
import { Search24 } from '@mysten/icons';
import { getObjectFields, getObjectType } from '@mysten/sui.js';
import { Text, LoadingIndicator, Combobox, ComboboxInput, ComboboxList } from '@mysten/ui';
import { useState } from 'react';

Expand All @@ -23,7 +22,10 @@ export function ObjectFieldsCard({ id }: ObjectFieldsProps) {
const { data, isLoading, isError } = useGetObject(id);
const [query, setQuery] = useState('');
const [activeFieldName, setActiveFieldName] = useState('');
const objectType = getObjectType(data!);
const objectType =
data?.data?.type ?? data?.data?.content?.dataType === 'package'
? 'package'
: data?.data?.content?.type;

// Get the packageId, moduleName, functionName from the objectType
const [packageId, moduleName, functionName] = objectType?.split('<')[0]?.split('::') || [];
Expand Down Expand Up @@ -59,7 +61,8 @@ export function ObjectFieldsCard({ id }: ObjectFieldsProps) {
);
}

const fieldsData = getObjectFields(data!);
const fieldsData =
data.data?.content?.dataType === 'moveObject' ? data.data?.content?.fields : null;

const filteredFieldNames =
query === ''
Expand Down
9 changes: 6 additions & 3 deletions apps/explorer/src/components/Object/UnderlyingObjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

import { useGetDynamicFieldObject, useGetNormalizedMoveStruct } from '@mysten/core';
import { getObjectFields, getObjectType } from '@mysten/sui.js';
import { LoadingIndicator } from '@mysten/ui';

import { FieldItem } from './FieldItem';
Expand All @@ -23,7 +22,10 @@ export function UnderlyingObjectCard({
dynamicFieldType,
}: UnderlyingObjectCardProps) {
const { data, isLoading, isError, isFetched } = useGetDynamicFieldObject(parentId, name);
const objectType = data ? getObjectType(data!) : null;
const objectType =
data?.data?.type ??
(data?.data?.content?.dataType === 'package' ? 'package' : data?.data?.content?.type) ??
null;
// Get the packageId, moduleName, functionName from the objectType
const [packageId, moduleName, functionName] = objectType?.split('<')[0]?.split('::') || [];

Expand Down Expand Up @@ -60,7 +62,8 @@ export function UnderlyingObjectCard({
);
}

const fieldsData = getObjectFields(data);
const fieldsData =
data.data?.content?.dataType === 'moveObject' ? data.data?.content.fields : null;
// Return null if there are no fields
if (!fieldsData || !normalizedStruct?.fields || !objectType) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions apps/explorer/src/components/OwnedObjects/OwnedObject.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { type SuiObjectResponse, getObjectDisplay } from '@mysten/sui.js';
import { type SuiObjectResponse } from '@mysten/sui.js/client';

import { useResolveVideo } from '~/hooks/useResolveVideo';
import { ObjectDetails } from '~/ui/ObjectDetails';
Expand All @@ -14,7 +14,7 @@ type OwnedObjectTypes = {

export default function OwnedObject({ obj }: OwnedObjectTypes) {
const video = useResolveVideo(obj);
const displayMeta = getObjectDisplay(obj).data;
const displayMeta = obj.data?.display?.data;

return (
<ObjectDetails
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/src/components/Table/SuiAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { CoinFormat, useFormatCoin } from '@mysten/core';
import { SUI_TYPE_ARG } from '@mysten/sui.js';
import { SUI_TYPE_ARG } from '@mysten/sui.js/utils';
import { Text } from '@mysten/ui';

export function SuiAmount({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import {
getExecutionStatusError,
getObjectId,
getTransactionDigest,
getTransactionEffects,
} from '@mysten/sui.js';

import { LinkGroup } from './LinkGroup';
import { Banner } from '~/ui/Banner';

import type { SuiTransactionBlockResponse, OwnedObjectRef } from '@mysten/sui.js/client';

function toObjectLink(object: OwnedObjectRef) {
return {
text: getObjectId(object.reference),
to: `/object/${encodeURIComponent(getObjectId(object.reference))}`,
text: object.reference.objectId,
to: `/object/${encodeURIComponent(object.reference.objectId)}`,
};
}

Expand All @@ -27,7 +20,7 @@ type FunctionExecutionResultProps = {
};

export function FunctionExecutionResult({ error, result, onClear }: FunctionExecutionResultProps) {
const adjError = error || (result && getExecutionStatusError(result)) || null;
const adjError = error || (result && result.effects?.status.error) || null;
const variant = adjError ? 'error' : 'message';
return (
<Banner icon={null} fullWidth variant={variant} spacing="lg" onDismiss={onClear}>
Expand All @@ -38,20 +31,20 @@ export function FunctionExecutionResult({ error, result, onClear }: FunctionExec
result
? [
{
text: getTransactionDigest(result),
to: `/txblock/${encodeURIComponent(getTransactionDigest(result))}`,
text: result.digest,
to: `/txblock/${encodeURIComponent(result.digest)}`,
},
]
: []
}
/>
<LinkGroup
title="Created"
links={(result && getTransactionEffects(result)?.created?.map(toObjectLink)) || []}
links={(result && result.effects?.created?.map(toObjectLink)) || []}
/>
<LinkGroup
title="Updated"
links={(result && getTransactionEffects(result)?.mutated?.map(toObjectLink)) || []}
links={(result && result.effects?.mutated?.map(toObjectLink)) || []}
/>
<LinkGroup title="Transaction failed" text={adjError} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { ArrowRight12 } from '@mysten/icons';
import {
getPureSerializationType,
getExecutionStatusType,
getExecutionStatusError,
TransactionBlock,
} from '@mysten/sui.js';
import { TransactionBlock, getPureSerializationType } from '@mysten/sui.js/transactions';
import { Button } from '@mysten/ui';
import { useWalletKit, ConnectButton } from '@mysten/wallet-kit';
import { useMutation } from '@tanstack/react-query';
Expand Down Expand Up @@ -81,8 +76,8 @@ export function ModuleFunction({
showInput: true,
},
});
if (getExecutionStatusType(result) === 'failure') {
throw new Error(getExecutionStatusError(result) || 'Transaction failed');
if (result.effects?.status.status === 'failure') {
throw new Error(result.effects.status.error || 'Transaction failed');
}
return result;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { useMemo } from 'react';

import type { SuiMoveAbilitySet } from '@mysten/sui.js';
import type { SuiMoveAbilitySet } from '@mysten/sui.js/client';

export function useFunctionTypeArguments(typeArguments: SuiMoveAbilitySet[]) {
return useMemo(
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/src/components/module/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import type { SuiMoveNormalizedType } from '@mysten/sui.js';
import type { SuiMoveNormalizedType } from '@mysten/sui.js/client';

/**
* Converts a SuiMoveNormalizedType to string
Expand Down
Loading

0 comments on commit b96dfa8

Please sign in to comment.