forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
explorer: moveCall execution (MystenLabs#6383)
* explorer: moveCall execution * execute a moveCall transaction using wallet-adapter * explorer: addresses pr comments * Label ui component * Input ui component * fixes useZodForm * removes useFieldArray * use 4 spacing instead of 3.75 * add input shadow color to config * use useMutation * add burner wallet adapter in dev
- Loading branch information
1 parent
ba6bd63
commit 97e96ba
Showing
15 changed files
with
382 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
apps/explorer/src/components/module/module-functions-interaction/useFunctionParamsDetails.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useMemo } from 'react'; | ||
|
||
import { getNormalizedFunctionParameterTypeDetails } from '../utils'; | ||
|
||
import type { SuiMoveNormalizedType } from '@mysten/sui.js'; | ||
|
||
export function useFunctionParamsDetails( | ||
params: SuiMoveNormalizedType[], | ||
functionTypeArgNames?: string[] | ||
) { | ||
return useMemo( | ||
() => | ||
params | ||
.map((aParam) => | ||
getNormalizedFunctionParameterTypeDetails( | ||
aParam, | ||
functionTypeArgNames | ||
) | ||
) | ||
.filter(({ isTxContext }) => !isTxContext), | ||
[params, functionTypeArgNames] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { SuiMoveNormalizedType } from '@mysten/sui.js'; | ||
|
||
/** | ||
* Converts a SuiMoveNormalizedType to string | ||
* @param param A parameter's normalized type of a function | ||
* @param functionTypeArgNames Parameters can be generic like 0x2::coin::Coin<T>. | ||
* T is provided on function level with the type_parameters field of SuiMoveNormalizedFunction that defines the abilities. | ||
* This parameter can be an array of strings that define the actual type or names like T1 that can be used to make the type of the parameter more specific. If | ||
* functionTypeArgNames or the index that the parameter expects are not defines then a default value T{index} is used. | ||
* @param str This function is recursive and this field is used to pass the already resolved type | ||
* @returns | ||
*/ | ||
export function normalizedFunctionParameterTypeToString( | ||
param: SuiMoveNormalizedType, | ||
functionTypeArgNames?: string[], | ||
str = '' | ||
): string { | ||
if (typeof param === 'string') { | ||
return str + param; | ||
} | ||
if ('TypeParameter' in param) { | ||
return ( | ||
str + | ||
(functionTypeArgNames?.[param.TypeParameter] ?? | ||
`T${param.TypeParameter}`) | ||
); | ||
} | ||
if ('Reference' in param || 'MutableReference' in param) { | ||
const p = | ||
'Reference' in param ? param.Reference : param.MutableReference; | ||
return normalizedFunctionParameterTypeToString( | ||
p, | ||
functionTypeArgNames, | ||
str | ||
); | ||
} | ||
if ('Vector' in param) { | ||
return ( | ||
normalizedFunctionParameterTypeToString( | ||
param.Vector, | ||
functionTypeArgNames, | ||
`${str}Vector<` | ||
) + '>' | ||
); | ||
} | ||
if ('Struct' in param) { | ||
const theType = param.Struct; | ||
const theTypeArgs = theType.type_arguments; | ||
const theTypeArgsStr = theTypeArgs | ||
.map((aTypeArg) => | ||
normalizedFunctionParameterTypeToString( | ||
aTypeArg, | ||
functionTypeArgNames | ||
) | ||
) | ||
.join(', '); | ||
return `${[theType.address, theType.module, theType.name].join('::')}${ | ||
theTypeArgsStr ? `<${theTypeArgsStr}>` : '' | ||
}`; | ||
} | ||
return str; | ||
} | ||
|
||
export function getNormalizedFunctionParameterTypeDetails( | ||
param: SuiMoveNormalizedType, | ||
functionTypeArgNames?: string[] | ||
) { | ||
const paramTypeText = normalizedFunctionParameterTypeToString( | ||
param, | ||
functionTypeArgNames | ||
); | ||
return { | ||
isTxContext: paramTypeText === '0x2::tx_context::TxContext', | ||
paramTypeText, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { zodResolver } from '@hookform/resolvers/zod'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
import type { UseFormProps } from 'react-hook-form'; | ||
import type { ZodSchema, TypeOf } from 'zod'; | ||
|
||
interface UseZodFormProps<T extends ZodSchema<any>> | ||
extends UseFormProps<TypeOf<T>> { | ||
schema: T; | ||
} | ||
|
||
export const useZodForm = <T extends ZodSchema<any>>({ | ||
schema, | ||
...formConfig | ||
}: UseZodFormProps<T>) => { | ||
return useForm({ | ||
...formConfig, | ||
resolver: zodResolver(schema), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.