-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Add hook with logic to check if an asset is 'Transferable…
…'. (#4159) * feat(tooling-core): Add hook with logic to check if an asset is 'Transferabe'. Remove old util * feat(apps-core): Use useQuery in place of useEffect in useIsAssetTransferable * feat(apps-core): Improve early return condition in useIsAssetTransferable * feat(apps-core): Improve per PR comments
- Loading branch information
Showing
7 changed files
with
65 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useIotaClient } from '@iota/dapp-kit'; | ||
import { IotaMoveNormalizedStruct, IotaObjectData } from '@iota/iota-sdk/client'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
function getObjectTypeParams(obj: IotaObjectData | null | undefined) { | ||
const objectType = | ||
obj?.type ?? | ||
(obj?.content?.dataType === 'package' ? 'package' : obj?.content?.type) ?? | ||
null; | ||
|
||
return objectType?.split('<')[0]?.split('::') || []; | ||
} | ||
|
||
export function useIsAssetTransferable(obj: IotaObjectData | null | undefined) { | ||
const client = useIotaClient(); | ||
const [packageId, moduleName, functionName] = getObjectTypeParams(obj); | ||
|
||
return useQuery({ | ||
// eslint-disable-next-line @tanstack/query/exhaustive-deps | ||
queryKey: ['is-asset-transferable', packageId, moduleName, functionName], | ||
queryFn: async () => { | ||
if (!packageId || !moduleName || !functionName) { | ||
return undefined; | ||
} | ||
|
||
return await client.getNormalizedMoveStruct({ | ||
package: packageId, | ||
module: moduleName, | ||
struct: functionName, | ||
}); | ||
}, | ||
select: (moveNormalizedStruct: IotaMoveNormalizedStruct | undefined): boolean => { | ||
if (!moveNormalizedStruct) { | ||
return false; | ||
} | ||
|
||
const structAbilities = moveNormalizedStruct?.abilities?.abilities ?? null; | ||
|
||
if (!structAbilities) { | ||
return false; | ||
} | ||
|
||
return structAbilities.includes('Store'); | ||
}, | ||
enabled: !!packageId && !!moduleName && !!functionName, | ||
}); | ||
} |
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 was deleted.
Oops, something went wrong.
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