diff --git a/components/account/grants.js b/components/account/grants.js deleted file mode 100644 index 62fdfd73..00000000 --- a/components/account/grants.js +++ /dev/null @@ -1,17 +0,0 @@ -import ToggleStorageBridgeAuthorization from "../repository/toggleStorageBridgeAuthorization"; -import ToggleGitServerAuthorization from "../repository/toggleGitServerAuthorization"; - -function AccountGrants({ address, ...props }) { - return ( -
-
- -
-
- -
-
- ); -} - -export default AccountGrants; diff --git a/components/dashboard/dao.js b/components/dashboard/dao.js index 00f0fd79..26ad2783 100644 --- a/components/dashboard/dao.js +++ b/components/dashboard/dao.js @@ -3,7 +3,6 @@ import Link from "next/link"; import { connect, useDispatch } from "react-redux"; import DAOMembersList from "./DAOMembersList"; import { createGroupProposal } from "../../store/actions/dao"; -import AccountGrants from "../account/grants"; import GreetDao from "../greetDao"; import { useApiClient } from "../../context/ApiClientContext"; import getGroupInfo from "../../helpers/getGroupInfo"; @@ -373,13 +372,6 @@ function DaoDashboard({ dao = {}, advanceUser, ...props }) { onRefreshProposals={fetchProposals} /> ); - case "authorizations": - return ( -
-

Authorizations

- -
- ); default: return null; } diff --git a/components/repository/cloneRepoInfo.js b/components/repository/cloneRepoInfo.js index 1664a469..9431ff55 100644 --- a/components/repository/cloneRepoInfo.js +++ b/components/repository/cloneRepoInfo.js @@ -1,40 +1,51 @@ import { useEffect, useState } from "react"; import { connect } from "react-redux"; import { notify } from "reapop"; +import { useApiClient } from "../../context/ApiClientContext"; -function CloneRepoInfo({ remoteUrl, backups, ...props }) { +function CloneRepoInfo({ remoteUrl, repositoryId, ...props }) { const [tab, setTab] = useState("gitopia"); const [cloneCmd, setCloneCmd] = useState("git clone " + remoteUrl); - const [isIpfsEnabled, setIsIpfsEnabled] = useState(false); - const [ipfsLatestCid, setIpfsLatestCid] = useState(""); - const [isArweaveEnabled, setIsArweaveEnabled] = useState(false); - const [arweaveLatestCid, setArweaveLatestCid] = useState(""); + const [storageInfo, setStorageInfo] = useState(null); + const { storageApiClient } = useApiClient(); useEffect(() => { if (tab === "gitopia") { setCloneCmd("git clone " + remoteUrl); - } else if (tab === "ipfs") { - setCloneCmd("ipfs_clone " + remoteUrl); - } else if (tab === "arweave") { - setCloneCmd("arweave_clone " + remoteUrl); } }, [tab, remoteUrl]); useEffect(() => { - setIsIpfsEnabled(false); - setIsArweaveEnabled(false); - if (backups) { - backups.map((b) => { - if (b.store === "IPFS" && b.refs?.length) { - setIsIpfsEnabled(true); - setIpfsLatestCid(b.refs[b.refs.length - 1]); - } else if (b.store === "ARWEAVE" && b.refs?.length) { - setIsArweaveEnabled(true); - setArweaveLatestCid(b.refs[b.refs.length - 1]); + const fetchStorageInfo = async () => { + if (repositoryId && storageApiClient) { + try { + const response = await storageApiClient.queryRepositoryPackfile(repositoryId); + // log response + console.log(response); + setStorageInfo(response.data.packfile); + } catch (error) { + console.error("Error fetching storage info:", error); } - }); + } + }; + + if (tab === "storage") { + fetchStorageInfo(); + } + }, [tab, repositoryId, storageApiClient]); + + const formatSize = (bytes) => { + const units = ['B', 'KB', 'MB', 'GB']; + let size = bytes; + let unitIndex = 0; + + while (size >= 1024 && unitIndex < units.length - 1) { + size /= 1024; + unitIndex++; } - }, [backups]); + + return `${size.toFixed(2)} ${units[unitIndex]}`; + }; return (
@@ -66,36 +77,17 @@ function CloneRepoInfo({ remoteUrl, backups, ...props }) { > Gitopia Server - {isIpfsEnabled ? ( - - ) : ( - "" - )} - {isArweaveEnabled ? ( - - ) : ( - "" - )} +
{tab === "gitopia" ? ( <> @@ -130,95 +122,80 @@ function CloneRepoInfo({ remoteUrl, backups, ...props }) { Learn more - - ) : ( - "" - )} -
- {tab === "ipfs" || tab === "arweave" ? ( -
-
- {tab === "ipfs" ? ( - - ) : ( - - )} -
- - -
- ) : ( - "" - )} - {tab === "gitopia" ? ( -
- - + + + + +
- ) : ( - "" - )} - + + ) : tab === "storage" ? ( +
+ {storageInfo ? ( +
+
+ IPFS + Storage Information +
+
+
+ Provider: + + {storageInfo.creator} + +
+
+ Size: + {formatSize(parseInt(storageInfo.size))} +
+
+ IPFS CID: + + {storageInfo.cid} + +
+
+ Root Hash: + + {storageInfo.root_hash} + +
+
+
+ ) : ( +
Loading storage information...
+ )} +
+ ) : null} ); diff --git a/components/repository/mergePullRequestView.js b/components/repository/mergePullRequestView.js index 9a90bf5f..6207f034 100644 --- a/components/repository/mergePullRequestView.js +++ b/components/repository/mergePullRequestView.js @@ -3,14 +3,12 @@ import { useEffect, useState } from "react"; import { notify } from "reapop"; import { updatePullRequestState, - authorizeGitServer, mergePullRequest, mergePullRequestForDao, } from "../../store/actions/repository"; import pullRequestStateClass from "../../helpers/pullRequestStateClass"; import mergePullRequestCheck from "../../helpers/mergePullRequestCheck"; import getPullRequestMergePermission from "../../helpers/getPullRequestMergePermission"; -import getGitServerAuthorization from "../../helpers/getGitServerAuthStatus"; import getDao from "../../helpers/getDao"; import { useApiClient } from "../../context/ApiClientContext"; import { useRouter } from "next/router"; @@ -25,10 +23,6 @@ function MergePullRequestView({ const [stateClass, setStateClass] = useState(""); const [iconType, setIconType] = useState("check"); const [message, setMessage] = useState(""); - const [pullMergeAccess, setPullMergeAccess] = useState(false); - const [pullMergeAccessDialogShown, setPullMergeAccessDialogShown] = - useState(false); - const [isGrantingAccess, setIsGrantingAccess] = useState(false); const [requiresProposal, setRequiresProposal] = useState(false); const [isCreatingProposal, setIsCreatingProposal] = useState(false); const { @@ -135,16 +129,6 @@ function MergePullRequestView({ ); if (user && user.havePermission) { - let access = await getGitServerAuthorization( - apiClient, - props.selectedAddress - ); - if (!access) { - setPullMergeAccessDialogShown(true); - setIsMerging(false); - return; - } - const res = await props.mergePullRequest( apiClient, cosmosBankApiClient, @@ -183,17 +167,6 @@ function MergePullRequestView({ } }, [pullRequest, props.selectedAddress, requiresProposal]); - const refreshPullMergeAccess = async (mergeAfter = false) => { - setPullMergeAccess( - await getGitServerAuthorization(apiClient, props.selectedAddress) - ); - if (mergeAfter) setTimeout(mergePull, 0); - }; - - useEffect(() => { - refreshPullMergeAccess(); - }, [props.selectedAddress]); - const getMergeButtonText = () => { if (isCreatingProposal) return "Creating Proposal..."; if (isMerging) return "Merging..."; @@ -284,56 +257,6 @@ function MergePullRequestView({ )} - - -
-
-

- Gitopia data server does not have repository merge access on behalf - of your account. -

-

Server Address:

-

- {process.env.NEXT_PUBLIC_GIT_SERVER_WALLET_ADDRESS} -

-
- - -
-
-
); } @@ -347,7 +270,6 @@ const mapStateToProps = (state) => { export default connect(mapStateToProps, { notify, updatePullRequestState, - authorizeGitServer, mergePullRequest, mergePullRequestForDao, })(MergePullRequestView); diff --git a/components/repository/toggleGitServerAuthorization.js b/components/repository/toggleGitServerAuthorization.js deleted file mode 100644 index 3bda903a..00000000 --- a/components/repository/toggleGitServerAuthorization.js +++ /dev/null @@ -1,76 +0,0 @@ -import { useEffect, useState } from "react"; -import { connect } from "react-redux"; -import { updateAddressGrant } from "../../store/actions/user"; -import getGitServerAuthStatus from "../../helpers/getGitServerAuthStatus"; -import { useApiClient } from "../../context/ApiClientContext"; - -function ToggleGitServerAuthorization({ address, onSuccess, ...props }) { - const [currentState, setCurrentState] = useState(false); - const [isToggling, setIsToggling] = useState(true); - const { apiClient, cosmosBankApiClient, cosmosFeeegrantApiClient } = - useApiClient(); - - const toggleGrant = async () => { - setIsToggling(true); - const res = await props.updateAddressGrant( - apiClient, - cosmosBankApiClient, - cosmosFeeegrantApiClient, - address, - 0, - !currentState - ); - if (res && res.code === 0) { - if (onSuccess) await onSuccess(!currentState); - setCurrentState(!currentState); - } - setIsToggling(false); - }; - - useEffect(() => { - async function initAddress() { - setIsToggling(true); - setCurrentState(await getGitServerAuthStatus(apiClient, address)); - setIsToggling(false); - } - initAddress(); - }, [address]); - - return ( - - ); -} - -const mapStateToProps = (state) => { - return { - selectedAddress: state.wallet.selectedAddress, - }; -}; - -export default connect(mapStateToProps, { updateAddressGrant })( - ToggleGitServerAuthorization -); diff --git a/components/repository/toggleStorageBridgeAuthorization.js b/components/repository/toggleStorageBridgeAuthorization.js deleted file mode 100644 index d87f1102..00000000 --- a/components/repository/toggleStorageBridgeAuthorization.js +++ /dev/null @@ -1,76 +0,0 @@ -import { useEffect, useState } from "react"; -import { connect } from "react-redux"; -import { updateAddressGrant } from "../../store/actions/user"; -import getStorageBridgeAuthStatus from "../../helpers/getStorageBridgeAuthStatus"; -import { useApiClient } from "../../context/ApiClientContext"; - -function ToggleStorageBridgeAuthorization({ address, onSuccess, ...props }) { - const [currentState, setCurrentState] = useState(false); - const [isToggling, setIsToggling] = useState(true); - const { apiClient, cosmosBankApiClient, cosmosFeegrantApiClient } = - useApiClient(); - - const toggleGrant = async () => { - setIsToggling(true); - const res = await props.updateAddressGrant( - apiClient, - cosmosBankApiClient, - cosmosFeegrantApiClient, - address, - 1, - !currentState - ); - if (res && res.code === 0) { - if (onSuccess) await onSuccess(!currentState); - setCurrentState(!currentState); - } - setIsToggling(false); - }; - - useEffect(() => { - async function initAddress() { - setIsToggling(true); - setCurrentState(await getStorageBridgeAuthStatus(apiClient, address)); - setIsToggling(false); - } - initAddress(); - }, [address]); - - return ( - - ); -} - -const mapStateToProps = (state) => { - return { - selectedAddress: state.wallet.selectedAddress, - }; -}; - -export default connect(mapStateToProps, { updateAddressGrant })( - ToggleStorageBridgeAuthorization -); diff --git a/context/ApiClientContext.js b/context/ApiClientContext.js index 46b899c8..ae864587 100644 --- a/context/ApiClientContext.js +++ b/context/ApiClientContext.js @@ -6,6 +6,7 @@ import { Api as CosmosFeegrantApi } from "../store/cosmos.feegrant.v1beta1/rest" import { Api as CosmosGovApi } from "../store/cosmos.gov.v1beta1/module/rest"; import { Api as IbcAppTransferApi } from "../store/ibc.applications.transfer.v1/module/rest"; import { Api as CosmosGroupApi } from "../store/cosmos.group.v1/rest"; +import { Api as StorageApi } from "../store/gitopia.gitopia.storage/rest"; import selectProvider from "../helpers/providerSelector"; import { setConfig } from "../store/actions/env"; @@ -22,6 +23,7 @@ export const ApiClientProvider = ({ children }) => { const [cosmosGovApiClient, setCosmosGovApiClient] = useState(null); const [ibcAppTransferApiClient, setIbcAppTransferApiClient] = useState(null); const [cosmosGroupApiClient, setCosmosGroupApiClient] = useState(null); + const [storageApiClient, setStorageApiClient] = useState(null); const [providerName, setProviderName] = useState(null); const [apiUrl, setApiUrl] = useState(null); const [rpcUrl, setRpcUrl] = useState(null); @@ -53,6 +55,11 @@ export const ApiClientProvider = ({ children }) => { }); setCosmosGroupApiClient(newCosmosGroupApiClient); + const newStorageApiClient = new StorageApi({ + baseURL: apiNode, + }); + setStorageApiClient(newStorageApiClient); + setProviderName(name); setApiUrl(apiNode); setRpcUrl(rpcNode); @@ -107,6 +114,7 @@ export const ApiClientProvider = ({ children }) => { cosmosGovApiClient, ibcAppTransferApiClient, cosmosGroupApiClient, + storageApiClient, updateApiClient, }} > diff --git a/helpers/getGitServerAuthStatus.js b/helpers/getGitServerAuthStatus.js deleted file mode 100644 index a01edb57..00000000 --- a/helpers/getGitServerAuthStatus.js +++ /dev/null @@ -1,17 +0,0 @@ -export default async function getGitServerAuthStatus(apiClient, userAddress) { - if (!userAddress) return null; - try { - const res = await apiClient.queryCheckGitServerAuthorization( - userAddress, - process.env.NEXT_PUBLIC_GIT_SERVER_WALLET_ADDRESS - ); - if (res.status === 200 && res.data.haveAuthorization) { - return true; - } else { - return false; - } - } catch (e) { - console.error(e); - return null; - } -} diff --git a/helpers/getStorageBridgeAuthStatus.js b/helpers/getStorageBridgeAuthStatus.js deleted file mode 100644 index 9dfecd77..00000000 --- a/helpers/getStorageBridgeAuthStatus.js +++ /dev/null @@ -1,22 +0,0 @@ -import { useApiClient } from "../context/ApiClientContext"; - -export default async function getStorageBridgeAuthStatus( - apiClient, - userAddress -) { - if (!userAddress) return null; - try { - const res = await apiClient.queryCheckStorageProviderAuthorization( - userAddress, - process.env.NEXT_PUBLIC_STORAGE_BRIDGE_WALLET_ADDRESS - ); - if (res.status === 200 && res.data.haveAuthorization) { - return true; - } else { - return false; - } - } catch (e) { - console.error(e); - return null; - } -} diff --git a/helpers/gitopiaLive.js b/helpers/gitopiaLive.js index 6308392d..a1dbcd06 100644 --- a/helpers/gitopiaLive.js +++ b/helpers/gitopiaLive.js @@ -289,6 +289,7 @@ function GitopiaLive(props) { "/" + props.repository.name } + repositoryId={props.repository.id} /> ) : ( diff --git a/pages/[userId]/[repositoryId]/fork.js b/pages/[userId]/[repositoryId]/fork.js index ad212e2d..fcf6b03c 100644 --- a/pages/[userId]/[repositoryId]/fork.js +++ b/pages/[userId]/[repositoryId]/fork.js @@ -12,10 +12,8 @@ import useRepository from "../../../hooks/useRepository"; import TextInput from "../../../components/textInput"; import { forkRepository, - authorizeGitServer, } from "../../../store/actions/repository"; import { useRouter } from "next/router"; -import getGitServerAuthorization from "../../../helpers/getGitServerAuthStatus"; import { useApiClient } from "../../../context/ApiClientContext"; export async function getStaticProps() { @@ -63,9 +61,6 @@ function RepositoryInvokeForkView(props) { ); const [isForking, setIsForking] = useState(false); const [forkingSuccess, setForkingSuccess] = useState(false); - const [forkingAccess, setForkingAccess] = useState(false); - const [grantAccessDialogShown, setGrantAccessDialogShown] = useState(false); - const [isGrantingAccess, setIsGrantingAccess] = useState(false); const sanitizedNameTest = new RegExp(/[^\w.-]/g); const router = useRouter(); @@ -125,14 +120,6 @@ function RepositoryInvokeForkView(props) { }; const invokeForkRepository = async () => { - let forkingAccess = await getGitServerAuthorization( - apiClient, - props.selectedAddress - ); - if (!forkingAccess) { - setGrantAccessDialogShown(true); - return; - } setIsForking(true); let validate = await validateRepository(); console.log(validate); @@ -163,11 +150,7 @@ function RepositoryInvokeForkView(props) { useEffect(() => { setForkRepositoryName(repository?.name || ""); setForkRepositoryDescription(repository?.description || ""); - if (repository?.owner?.address === props.currentDashboard) { - setOwnerId(""); - } else { - setOwnerId(props.currentDashboard); - } + setOwnerId(props.currentDashboard); setForkOnlyOneBranchName(repository?.defaultBranch); }, [repository, props.currentDashboard]); @@ -358,68 +341,6 @@ function RepositoryInvokeForkView(props) { - -
-
-

- Gitopia data server does not have repository forking access on - behalf of your account. -

-

Server Address:

-

- {process.env.NEXT_PUBLIC_GIT_SERVER_WALLET_ADDRESS} -

-
- - -
-
-