Skip to content

Commit

Permalink
Add error message parsing for Lite DAO Creation and other error handl…
Browse files Browse the repository at this point in the history
…ing improvements (#675)

Signed-off-by: Manank Patni <[email protected]>
  • Loading branch information
Man-Jain authored Sep 30, 2023
1 parent 490b003 commit 39790d1
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 70 deletions.
7 changes: 4 additions & 3 deletions src/modules/lite/creator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
})
Expand Down
11 changes: 10 additions & 1 deletion src/modules/lite/explorer/components/DaoCardDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ export const DaoCardDetail: React.FC<DaoCardDetailProps> = ({ 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]
Expand Down
48 changes: 29 additions & 19 deletions src/modules/lite/explorer/components/ProposalList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/modules/lite/explorer/hooks/useCommunity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const useCommunity = (daoId: string, isUpdated?: number) => {
}
setCommunity(record)
})
} catch {
} catch (error) {
console.log("error: ", error)
return
}
}
Expand Down
33 changes: 19 additions & 14 deletions src/modules/lite/explorer/hooks/useCommunityToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@ export const useCommunityToken = (communityId: any) => {
const [token, setToken] = useState<CommunityToken>()
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()
Expand Down
5 changes: 3 additions & 2 deletions src/modules/lite/explorer/hooks/useHasVoted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
})
Expand Down
4 changes: 2 additions & 2 deletions src/modules/lite/explorer/hooks/usePoll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
})
Expand Down
33 changes: 19 additions & 14 deletions src/modules/lite/explorer/hooks/usePollChoices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion src/modules/lite/explorer/hooks/useToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const useToken = (daoId: string | undefined) => {
setTokenAddress(record.tokenAddress)
})
}
} catch {
} catch (error) {
console.log("error: ", error)
return
}
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/lite/explorer/pages/CreateProposal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/modules/lite/explorer/pages/ProposalDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
})
Expand Down
7 changes: 6 additions & 1 deletion src/services/contracts/baseDAO/hooks/useOriginate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down
1 change: 0 additions & 1 deletion src/services/lite/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
20 changes: 10 additions & 10 deletions src/services/services/lite/lite-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -37,10 +36,17 @@ export const getDAO = async (address: string) => {
}

export const getLiteDAOs = async (network: string) => {
const response = await axios.post<Community[]>(`${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 = {
Expand Down Expand Up @@ -140,12 +146,6 @@ export const joinLiteCommunity = async (signature: string, publicKey: string | u
return resp
}

export const updateLiteCommunity = async () => {
const response = await axios.get<any>(`${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",
Expand Down

0 comments on commit 39790d1

Please sign in to comment.