diff --git a/src/modules/lite/creator/index.tsx b/src/modules/lite/creator/index.tsx index 86cb7509..4be97433 100644 --- a/src/modules/lite/creator/index.tsx +++ b/src/modules/lite/creator/index.tsx @@ -421,17 +421,18 @@ export const CommunityCreator: React.FC = () => { } const resp = await saveLiteCommunity(signature, publicKey, payloadBytes) - const response = await resp.json() + const data = await resp.json() if (resp.ok) { openNotification({ - message: "Community created!", + message: "Community created! Checkout the DAO in explorer page", autoHideDuration: 3000, variant: "success" }) navigate.push("/explorer") } else { + console.log("Error: ", data.message) openNotification({ - message: response.message, + message: data.message, autoHideDuration: 3000, variant: "error" }) diff --git a/src/modules/lite/explorer/components/DaoCardDetail.tsx b/src/modules/lite/explorer/components/DaoCardDetail.tsx index 244e2a3a..19b8b7dc 100644 --- a/src/modules/lite/explorer/components/DaoCardDetail.tsx +++ b/src/modules/lite/explorer/components/DaoCardDetail.tsx @@ -64,7 +64,16 @@ export const DaoCardDetail: React.FC = ({ community, setIsUp const updateCommunityCount = useCallback( async (count: number) => { if (community) { - updateCount(community._id, count) + try { + const resp = await updateCount(community._id, count) + const respData = await resp.json() + + if (!resp.ok) { + console.log(respData.message) + } + } catch (error) { + console.log("Error: ", error) + } } }, [community] diff --git a/src/modules/lite/explorer/components/ProposalList.tsx b/src/modules/lite/explorer/components/ProposalList.tsx index 2d546403..2351b46e 100644 --- a/src/modules/lite/explorer/components/ProposalList.tsx +++ b/src/modules/lite/explorer/components/ProposalList.tsx @@ -64,28 +64,38 @@ export const ProposalList: React.FC<{ polls: Poll[]; id: string | undefined; dao useMemo(() => { async function getPollToken() { - if (polls && polls.length > 0) { - polls.forEach(async poll => { - await fetch(`${getEnv(EnvKey.REACT_APP_LITE_API_URL)}/token/${communityId}`).then(async response => { - if (!response.ok) { - const data = await response.json() - openNotification({ - message: data.message, - autoHideDuration: 2000, - variant: "error" - }) + try { + if (polls && polls.length > 0) { + polls.forEach(async poll => { + await fetch(`${getEnv(EnvKey.REACT_APP_LITE_API_URL)}/token/${communityId}`).then(async response => { + if (!response.ok) { + const data = await response.json() + openNotification({ + message: data.message, + autoHideDuration: 2000, + variant: "error" + }) + return + } + const record: CommunityToken = await response.json() + if (!record) { + return + } + poll.tokenAddress = record.tokenAddress + poll.tokenSymbol = record.symbol + poll.tokenDecimals = record.decimals return - } - const record: CommunityToken = await response.json() - if (!record) { - return - } - poll.tokenAddress = record.tokenAddress - poll.tokenSymbol = record.symbol - poll.tokenDecimals = record.decimals - return + }) }) + } + } catch (error: any) { + console.log("error: ", error) + openNotification({ + message: error.message, + autoHideDuration: 2000, + variant: "error" }) + return } } getPollToken() diff --git a/src/modules/lite/explorer/hooks/useCommunity.tsx b/src/modules/lite/explorer/hooks/useCommunity.tsx index a424b886..2febfcbb 100644 --- a/src/modules/lite/explorer/hooks/useCommunity.tsx +++ b/src/modules/lite/explorer/hooks/useCommunity.tsx @@ -30,7 +30,8 @@ export const useCommunity = (daoId: string, isUpdated?: number) => { } setCommunity(record) }) - } catch { + } catch (error) { + console.log("error: ", error) return } } diff --git a/src/modules/lite/explorer/hooks/useCommunityToken.tsx b/src/modules/lite/explorer/hooks/useCommunityToken.tsx index 551e064c..67b50624 100644 --- a/src/modules/lite/explorer/hooks/useCommunityToken.tsx +++ b/src/modules/lite/explorer/hooks/useCommunityToken.tsx @@ -6,22 +6,27 @@ export const useCommunityToken = (communityId: any) => { const [token, setToken] = useState() useEffect(() => { async function fetchToken() { - if (communityId !== undefined) { - await fetch(`${getEnv(EnvKey.REACT_APP_LITE_API_URL)}/token/${String(communityId)}`).then(async response => { - if (!response.ok) { - const data = await response.json() - const message = data.message - return message - } + try { + if (communityId !== undefined) { + await fetch(`${getEnv(EnvKey.REACT_APP_LITE_API_URL)}/token/${String(communityId)}`).then(async response => { + if (!response.ok) { + const data = await response.json() + const message = data.message + return message + } - const record: CommunityToken = await response.json() - if (!record) { - return - } + const record: CommunityToken = await response.json() + if (!record) { + return + } - setToken(record) - return - }) + setToken(record) + return + }) + } + } catch (error) { + console.log("error: ", error) + return } } fetchToken() diff --git a/src/modules/lite/explorer/hooks/useHasVoted.tsx b/src/modules/lite/explorer/hooks/useHasVoted.tsx index 8766505a..7348657c 100644 --- a/src/modules/lite/explorer/hooks/useHasVoted.tsx +++ b/src/modules/lite/explorer/hooks/useHasVoted.tsx @@ -42,9 +42,10 @@ export const useHasVoted = (refresh?: number) => { return } ) - } catch { + } catch (error) { + console.log("error: ", error) openNotification({ - message: "An error has occurred", + message: "An error has occurred fetching vote status", autoHideDuration: 2000, variant: "error" }) diff --git a/src/modules/lite/explorer/hooks/usePoll.tsx b/src/modules/lite/explorer/hooks/usePoll.tsx index cdf5c8fb..c180e054 100644 --- a/src/modules/lite/explorer/hooks/usePoll.tsx +++ b/src/modules/lite/explorer/hooks/usePoll.tsx @@ -38,9 +38,9 @@ export const useSinglePoll = (pollId: string | undefined, id?: any, community?: return }) } catch (error) { - setPoll(undefined) + console.log("error: ", error) openNotification({ - message: "An error has occurred", + message: "An error has occurred fetching poll", autoHideDuration: 2000, variant: "error" }) diff --git a/src/modules/lite/explorer/hooks/usePollChoices.tsx b/src/modules/lite/explorer/hooks/usePollChoices.tsx index a4ddfe40..08b9a2bd 100644 --- a/src/modules/lite/explorer/hooks/usePollChoices.tsx +++ b/src/modules/lite/explorer/hooks/usePollChoices.tsx @@ -11,21 +11,26 @@ export const usePollChoices = (poll: Poll | undefined, refresh?: number) => { useEffect(() => { async function fetchChoices() { - if (poll) { - await fetch(`${getEnv(EnvKey.REACT_APP_LITE_API_URL)}/choices/${poll._id}/find`).then(async response => { - if (!response.ok) { - const data = await response.json() - openNotification({ - message: data.message, - autoHideDuration: 2000, - variant: "error" - }) + try { + if (poll) { + await fetch(`${getEnv(EnvKey.REACT_APP_LITE_API_URL)}/choices/${poll._id}/find`).then(async response => { + if (!response.ok) { + const data = await response.json() + openNotification({ + message: data.message, + autoHideDuration: 2000, + variant: "error" + }) + return + } + const records: Choice[] = await response.json() + setChoices(records) return - } - const records: Choice[] = await response.json() - setChoices(records) - return - }) + }) + } + } catch (error) { + console.log("error: ", error) + return } } fetchChoices() diff --git a/src/modules/lite/explorer/hooks/useToken.tsx b/src/modules/lite/explorer/hooks/useToken.tsx index a277f118..872ba922 100644 --- a/src/modules/lite/explorer/hooks/useToken.tsx +++ b/src/modules/lite/explorer/hooks/useToken.tsx @@ -30,7 +30,8 @@ export const useToken = (daoId: string | undefined) => { setTokenAddress(record.tokenAddress) }) } - } catch { + } catch (error) { + console.log("error: ", error) return } } diff --git a/src/modules/lite/explorer/pages/CreateProposal/index.tsx b/src/modules/lite/explorer/pages/CreateProposal/index.tsx index 9e95f61b..6c9b42fb 100644 --- a/src/modules/lite/explorer/pages/CreateProposal/index.tsx +++ b/src/modules/lite/explorer/pages/CreateProposal/index.tsx @@ -632,6 +632,7 @@ export const ProposalCreator: React.FC<{ id?: string; onClose?: any }> = props = ? navigate.push(`/explorer/dao/${daoId}/proposals`) : navigate.push(`/explorer/lite/dao/${id}/community`) } else { + console.log("Error: ", respData.message) openNotification({ message: respData.message, autoHideDuration: 3000, diff --git a/src/modules/lite/explorer/pages/ProposalDetails/index.tsx b/src/modules/lite/explorer/pages/ProposalDetails/index.tsx index 450d4395..af96a785 100644 --- a/src/modules/lite/explorer/pages/ProposalDetails/index.tsx +++ b/src/modules/lite/explorer/pages/ProposalDetails/index.tsx @@ -108,6 +108,7 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => { setRefresh(Math.random()) setSelectedVotes([]) } else { + console.log("Error: ", response.message) openNotification({ message: response.message, autoHideDuration: 3000, @@ -118,7 +119,7 @@ export const ProposalDetails: React.FC<{ id: string }> = ({ id }) => { } catch (error) { console.log("error: ", error) openNotification({ - message: `Something went wrong!!`, + message: `Could not submit vote, Please Try Again!`, autoHideDuration: 3000, variant: "error" }) diff --git a/src/services/contracts/baseDAO/hooks/useOriginate.ts b/src/services/contracts/baseDAO/hooks/useOriginate.ts index 9d44a261..0e3f92b7 100644 --- a/src/services/contracts/baseDAO/hooks/useOriginate.ts +++ b/src/services/contracts/baseDAO/hooks/useOriginate.ts @@ -261,7 +261,12 @@ export const useOriginate = (template: DAOTemplate) => { const { signature, payloadBytes } = await getSignature(account, wallet, JSON.stringify(values)) const publicKey = (await wallet?.client.getActiveAccount())?.publicKey - await saveLiteCommunity(signature, publicKey, payloadBytes) + const resp = await saveLiteCommunity(signature, publicKey, payloadBytes) + const data = await resp.json() + if (!resp.ok) { + console.log("Error: ", data.message) + throw new Error(data.message) + } updatedStates[4] = { activeText: "", diff --git a/src/services/lite/utils.ts b/src/services/lite/utils.ts index 81d8f885..3fce0e8b 100644 --- a/src/services/lite/utils.ts +++ b/src/services/lite/utils.ts @@ -8,7 +8,6 @@ import { BeaconWallet } from "@taquito/beacon-wallet" import { RequestSignPayloadInput, SigningType } from "@airgap/beacon-sdk" import BigNumber from "bignumber.js" import { Network } from "services/beacon" -import axios from "axios" export const getCurrentBlock = async (network: Network) => { const url = `https://api.${networkNameMap[network]}.tzkt.io/v1/head` diff --git a/src/services/services/lite/lite-services.ts b/src/services/services/lite/lite-services.ts index 27202071..07f0105d 100644 --- a/src/services/services/lite/lite-services.ts +++ b/src/services/services/lite/lite-services.ts @@ -4,7 +4,6 @@ import { GET_DAO_QUERY, GET_PROPOSALS_QUERY, GET_PROPOSAL_QUERY, GET_XTZ_TRANSFE import { LambdaProposal, Proposal } from "../dao/mappers/proposal/types" import dayjs from "dayjs" import { BaseDAO } from "../../contracts/baseDAO" -import axios from "axios" import { EnvKey, getEnv } from "services/config" import { Network } from "services/beacon" @@ -37,10 +36,17 @@ export const getDAO = async (address: string) => { } export const getLiteDAOs = async (network: string) => { - const response = await axios.post(`${REACT_APP_LITE_API_URL}/daos/`, { - network + const resp = await fetch(`${REACT_APP_LITE_API_URL}/daos/`, { + method: "POST", + body: JSON.stringify({ + network + }), + headers: { + "Content-Type": "application/json" + } }) - const daos = response.data + + const daos: Community[] = await resp.json() const new_daos = daos.map(dao => { const new_dao: DAOListItem = { @@ -140,12 +146,6 @@ export const joinLiteCommunity = async (signature: string, publicKey: string | u return resp } -export const updateLiteCommunity = async () => { - const response = await axios.get(`${REACT_APP_LITE_API_URL}/daos/create/voting`) - const daos = response.data - console.log(daos) -} - export const saveLiteProposal = async (signature: string, publicKey: string | undefined, payloadBytes: string) => { const resp = await fetch(`${getEnv(EnvKey.REACT_APP_LITE_API_URL)}/poll/add`, { method: "POST",