Skip to content

Commit

Permalink
[dapp-kit] fix esm typescript types (#14586)
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 Nov 1, 2023
1 parent 1059576 commit b359868
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-bulldogs-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mysten/dapp-kit': minor
---

Fix how esm types are built
4 changes: 2 additions & 2 deletions sdk/dapp-kit/src/components/AccountDropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function AccountDropdownMenu({ currentAccount }: AccountDropdownMenuProps
<DropdownMenu.Trigger asChild>
<Button size="lg" className={styles.connectedAccount}>
<Text mono weight="bold">
{currentAccount.label ?? domain ?? formatAddress(currentAccount.address)}
{currentAccount.label ?? domain?.data ?? formatAddress(currentAccount.address)}
</Text>
<ChevronIcon />
</Button>
Expand Down Expand Up @@ -80,7 +80,7 @@ export function AccountDropdownMenuItem({
className={clsx(styles.menuItem, styles.switchAccountMenuItem)}
onSelect={() => switchAccount({ account })}
>
<Text mono>{account.label ?? domain ?? formatAddress(account.address)}</Text>
<Text mono>{account.label ?? domain?.data ?? formatAddress(account.address)}</Text>
{active ? <CheckIcon /> : null}
</DropdownMenu.Item>
);
Expand Down
4 changes: 2 additions & 2 deletions sdk/dapp-kit/src/hooks/useResolveSuiNSNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import type { ResolvedNameServiceNames } from '@mysten/sui.js/client';
import type { UseQueryOptions } from '@tanstack/react-query';
import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';

import { useSuiClientQuery } from './useSuiClientQuery.js';

Expand All @@ -12,7 +12,7 @@ export function useResolveSuiNSName(
UseQueryOptions<ResolvedNameServiceNames, Error, string | null, unknown[]>,
'queryFn' | 'queryKey'
>,
) {
): UseQueryResult<ResolvedNameServiceNames, Error> {
return useSuiClientQuery(
'resolveNameServiceNames',
{
Expand Down
8 changes: 6 additions & 2 deletions sdk/dapp-kit/src/hooks/useSuiClientInfiniteQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// SPDX-License-Identifier: Apache-2.0

import type { SuiClient } from '@mysten/sui.js/client';
import type { InfiniteData, UseInfiniteQueryOptions } from '@tanstack/react-query';
import type {
InfiniteData,
UseInfiniteQueryOptions,
UseInfiniteQueryResult,
} from '@tanstack/react-query';
import { useInfiniteQuery } from '@tanstack/react-query';

import type { PartialBy } from '../types/utilityTypes.js';
Expand Down Expand Up @@ -59,7 +63,7 @@ export function useSuiClientInfiniteQuery<
enabled = !!params,
...options
}: UseSuiClientInfiniteQueryOptions<T, TData> = {},
) {
): UseInfiniteQueryResult<TData, Error> {
const suiContext = useSuiClientContext();

return useInfiniteQuery({
Expand Down
4 changes: 2 additions & 2 deletions sdk/dapp-kit/src/hooks/useSuiClientMutation.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 { UseMutationOptions } from '@tanstack/react-query';
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';

import { useSuiClientContext } from './useSuiClient.js';
Expand All @@ -15,7 +15,7 @@ export type UseSuiClientMutationOptions<T extends keyof SuiRpcMethods> = Omit<
export function useSuiClientMutation<T extends keyof SuiRpcMethods>(
method: T,
options: UseSuiClientMutationOptions<T> = {},
) {
): UseMutationResult<SuiRpcMethods[T]['result'], Error, SuiRpcMethods[T]['params'], unknown[]> {
const suiContext = useSuiClientContext();

return useMutation({
Expand Down
4 changes: 2 additions & 2 deletions sdk/dapp-kit/src/hooks/useSuiClientQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import type { SuiClient } from '@mysten/sui.js/client';
import type { UseQueryOptions } from '@tanstack/react-query';
import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
import { useQuery } from '@tanstack/react-query';

import type { PartialBy } from '../types/utilityTypes.js';
Expand Down Expand Up @@ -42,7 +42,7 @@ export function useSuiClientQuery<
...args: undefined extends SuiRpcMethods[T]['params']
? [method: T, params?: SuiRpcMethods[T]['params'], options?: UseSuiClientQueryOptions<T, TData>]
: [method: T, params: SuiRpcMethods[T]['params'], options?: UseSuiClientQueryOptions<T, TData>]
) {
): UseQueryResult<SuiRpcMethods[T]['result'], Error> {
const [method, params, { queryKey = [], ...options } = {}] = args as [
method: T,
params?: SuiRpcMethods[T]['params'],
Expand Down
4 changes: 3 additions & 1 deletion sdk/dapp-kit/src/hooks/wallet/useAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import type { WalletAccount } from '@mysten/wallet-standard';

import { useWalletStore } from './useWalletStore.js';

/**
* Retrieves a list of connected accounts authorized by the dApp.
*/
export function useAccounts() {
export function useAccounts(): readonly WalletAccount[] {
return useWalletStore((state) => state.accounts);
}
9 changes: 7 additions & 2 deletions sdk/dapp-kit/src/hooks/wallet/useConnectWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
WalletAccount,
WalletWithRequiredFeatures,
} from '@mysten/wallet-standard';
import type { UseMutationOptions } from '@tanstack/react-query';
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';

import { walletMutationKeys } from '../../constants/walletMutationKeys.js';
Expand All @@ -34,7 +34,12 @@ type UseConnectWalletMutationOptions = Omit<
export function useConnectWallet({
mutationKey,
...mutationOptions
}: UseConnectWalletMutationOptions = {}) {
}: UseConnectWalletMutationOptions = {}): UseMutationResult<
ConnectWalletResult,
Error,
ConnectWalletArgs,
unknown
> {
const setWalletConnected = useWalletStore((state) => state.setWalletConnected);
const setConnectionStatus = useWalletStore((state) => state.setConnectionStatus);

Expand Down
4 changes: 3 additions & 1 deletion sdk/dapp-kit/src/hooks/wallet/useCurrentAccount.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import type { WalletAccount } from '@mysten/wallet-standard';

import { useWalletStore } from './useWalletStore.js';

/**
* Retrieves the wallet account that is currently selected, if one exists.
*/
export function useCurrentAccount() {
export function useCurrentAccount(): WalletAccount | null {
return useWalletStore((state) => state.currentAccount);
}
8 changes: 6 additions & 2 deletions sdk/dapp-kit/src/hooks/wallet/useDisconnectWallet.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 { UseMutationOptions } from '@tanstack/react-query';
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';

import { walletMutationKeys } from '../../constants/walletMutationKeys.js';
Expand All @@ -22,7 +22,11 @@ type UseDisconnectWalletMutationOptions = Omit<
export function useDisconnectWallet({
mutationKey,
...mutationOptions
}: UseDisconnectWalletMutationOptions = {}) {
}: UseDisconnectWalletMutationOptions = {}): UseMutationResult<
void,
UseDisconnectWalletError,
void
> {
const { currentWallet } = useCurrentWallet();
const setWalletDisconnected = useWalletStore((state) => state.setWalletDisconnected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
SuiSignAndExecuteTransactionBlockInput,
SuiSignAndExecuteTransactionBlockOutput,
} from '@mysten/wallet-standard';
import type { UseMutationOptions } from '@tanstack/react-query';
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';

import { walletMutationKeys } from '../../constants/walletMutationKeys.js';
Expand Down Expand Up @@ -51,7 +51,11 @@ export function useSignAndExecuteTransactionBlock({
mutationKey,
executeFromWallet,
...mutationOptions
}: UseSignAndExecuteTransactionBlockMutationOptions = {}) {
}: UseSignAndExecuteTransactionBlockMutationOptions = {}): UseMutationResult<
UseSignAndExecuteTransactionBlockResult,
UseSignAndExecuteTransactionBlockError,
UseSignAndExecuteTransactionBlockArgs
> {
const { currentWallet } = useCurrentWallet();
const currentAccount = useCurrentAccount();
const client = useSuiClient();
Expand Down
8 changes: 6 additions & 2 deletions sdk/dapp-kit/src/hooks/wallet/useSignPersonalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
SuiSignPersonalMessageInput,
SuiSignPersonalMessageOutput,
} from '@mysten/wallet-standard';
import type { UseMutationOptions } from '@tanstack/react-query';
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';

import {
Expand Down Expand Up @@ -44,7 +44,11 @@ type UseSignPersonalMessageMutationOptions = Omit<
export function useSignPersonalMessage({
mutationKey,
...mutationOptions
}: UseSignPersonalMessageMutationOptions = {}) {
}: UseSignPersonalMessageMutationOptions = {}): UseMutationResult<
UseSignPersonalMessageResult,
UseSignPersonalMessageError,
UseSignPersonalMessageArgs
> {
const { currentWallet } = useCurrentWallet();
const currentAccount = useCurrentAccount();

Expand Down
8 changes: 6 additions & 2 deletions sdk/dapp-kit/src/hooks/wallet/useSignTransactionBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
SuiSignTransactionBlockInput,
SuiSignTransactionBlockOutput,
} from '@mysten/wallet-standard';
import type { UseMutationOptions } from '@tanstack/react-query';
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';

import {
Expand Down Expand Up @@ -44,7 +44,11 @@ type UseSignTransactionBlockMutationOptions = Omit<
export function useSignTransactionBlock({
mutationKey,
...mutationOptions
}: UseSignTransactionBlockMutationOptions = {}) {
}: UseSignTransactionBlockMutationOptions = {}): UseMutationResult<
UseSignTransactionBlockResult,
UseSignTransactionBlockError,
UseSignTransactionBlockArgs
> {
const { currentWallet } = useCurrentWallet();
const currentAccount = useCurrentAccount();

Expand Down
8 changes: 6 additions & 2 deletions sdk/dapp-kit/src/hooks/wallet/useSwitchAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import type { WalletAccount } from '@mysten/wallet-standard';
import type { UseMutationOptions } from '@tanstack/react-query';
import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';

import { walletMutationKeys } from '../../constants/walletMutationKeys.js';
Expand All @@ -29,7 +29,11 @@ type UseSwitchAccountMutationOptions = Omit<
export function useSwitchAccount({
mutationKey,
...mutationOptions
}: UseSwitchAccountMutationOptions = {}) {
}: UseSwitchAccountMutationOptions = {}): UseMutationResult<
SwitchAccountResult,
UseSwitchAccountError,
SwitchAccountArgs
> {
const { currentWallet } = useCurrentWallet();
const setAccountSwitched = useWalletStore((state) => state.setAccountSwitched);

Expand Down
4 changes: 3 additions & 1 deletion sdk/dapp-kit/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"module": "Node16",
"moduleResolution": "Node16",
"outDir": "dist/esm"
}
}

0 comments on commit b359868

Please sign in to comment.