Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mahalo module verify #692

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Improvements

- [#692](https://github.com/alleslabs/celatone-frontend/pull/692) Add verify link for mahalo
- [#675](https://github.com/alleslabs/celatone-frontend/pull/675) Make module links clickable with command/ctrl and add copier for struct names
- [#674](https://github.com/alleslabs/celatone-frontend/pull/674) Adjust contract list card and microcopies
- [#672](https://github.com/alleslabs/celatone-frontend/pull/672) Refactor balances
Expand Down
3 changes: 3 additions & 0 deletions src/config/chain/initia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const INITIA_CHAIN_CONFIGS: ChainConfigs = {
enabled: true,
moduleMaxFileSize: 1_048_576,
decodeApi: INITIA_DECODER,
verify: "https://compiler.mahalo-1.initia.xyz/contracts/verify",
},
pool: {
enabled: false,
Expand Down Expand Up @@ -74,6 +75,7 @@ export const INITIA_CHAIN_CONFIGS: ChainConfigs = {
enabled: true,
moduleMaxFileSize: 1_048_576,
decodeApi: INITIA_DECODER,
verify: "",
},
pool: {
enabled: false,
Expand Down Expand Up @@ -171,6 +173,7 @@ export const INITIA_CHAIN_CONFIGS: ChainConfigs = {
enabled: true,
moduleMaxFileSize: 1_048_576,
decodeApi: INITIA_DECODER,
verify: "https://stone-compiler.initia.tech/contracts/verify",
},
pool: {
enabled: false,
Expand Down
1 change: 1 addition & 0 deletions src/config/chain/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type MoveConfig =
enabled: true;
moduleMaxFileSize: number;
decodeApi: string;
verify: string;
}
| { enabled: false };

Expand Down
7 changes: 6 additions & 1 deletion src/lib/components/module/ModuleSourceCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export const ModuleSourceCode = ({ sourceCode }: ModuleSourceCodeProps) => {
<Text fontWeight={600} variant="body1" color="text.main">
Module Source Code
</Text>
<Text fontWeight={600} variant="body2" color="text.dark">
<Text
fontWeight={600}
variant="body2"
color="text.dark"
textAlign="start"
>
The source code is uploaded by the deployer and pulled from
Initia API
</Text>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/pages/module-details/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Flex, Tabs, TabList, TabPanel, TabPanels } from "@chakra-ui/react";
import { isUndefined } from "lodash";
import { useRouter } from "next/router";
import { useState, useCallback, useEffect } from "react";

Expand Down Expand Up @@ -185,7 +186,8 @@ export const ModuleDetailsBody = ({ moduleData }: ModuleDetailsBodyProps) => {
viewFns={moduleData.viewFunctions.length}
executeFns={moduleData.executeFunctions.length}
allTxsCount={
moduleTxsCount && moduleHistoriesCount
!isUndefined(moduleTxsCount) &&
!isUndefined(moduleHistoriesCount)
? moduleTxsCount + moduleHistoriesCount
: undefined
}
Expand Down
6 changes: 2 additions & 4 deletions src/lib/services/move/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,12 @@ export interface ModuleVerificationInternal
}

export const getModuleVerificationStatus = async (
endpoint: string,
address: MoveAccountAddr,
moduleName: string
): Promise<Nullable<ModuleVerificationInternal>> =>
// TODO: move url to base api route? wait for celatone api implementation?
axios
.get<ModuleVerificationReturn>(
`https://stone-compiler.initia.tech/contracts/verify/${address}/${moduleName}`
)
.get<ModuleVerificationReturn>(`${endpoint}/${address}/${moduleName}`)
.then(({ data }) => ({
...snakeToCamel(data),
moduleAddress: data.module_address,
Expand Down
14 changes: 9 additions & 5 deletions src/lib/services/move/moduleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,15 @@ export const useVerifyModule = ({
}: {
address: Option<MoveAccountAddr>;
moduleName: Option<string>;
}): UseQueryResult<Nullable<ModuleVerificationInternal>> =>
useQuery(
[CELATONE_QUERY_KEYS.MODULE_VERIFICATION, address, moduleName],
}): UseQueryResult<Nullable<ModuleVerificationInternal>> => {
const move = useMoveConfig({ shouldRedirect: false });
const endpoint = move.enabled ? move.verify : "";

return useQuery(
[CELATONE_QUERY_KEYS.MODULE_VERIFICATION, endpoint, address, moduleName],
() => {
if (!address || !moduleName) return null;
return getModuleVerificationStatus(address, moduleName);
if (!endpoint || !address || !moduleName) return null;
return getModuleVerificationStatus(endpoint, address, moduleName);
},
{
enabled: Boolean(address && moduleName),
Expand All @@ -155,6 +158,7 @@ export const useVerifyModule = ({
keepPreviousData: true,
}
);
};

export const useFunctionView = ({
moduleAddress,
Expand Down
Loading