Skip to content

Commit

Permalink
Bugs Fixes and Improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Manank Patni <[email protected]>
  • Loading branch information
Man-Jain committed Jul 22, 2023
1 parent 6c8903c commit 8b9dab6
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 81 deletions.
3 changes: 3 additions & 0 deletions src/modules/creator/deployment/steps/Distribution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ const validateForm = (values: TokenDistributionSettings) => {
if (values.totalAmount && values.totalAmount.minus(new BigNumber(getTotal(values.holders))) < new BigNumber(0)) {
errors.totalAmount = "Available balance has to be greater that the total supply"
}
if (values.totalAmount && values.totalAmount.gt(new BigNumber(getTotal(values.holders)))) {
errors.totalAmount = "Total Supply not fully allocated"
}
})

return errors
Expand Down
15 changes: 3 additions & 12 deletions src/modules/creator/deployment/steps/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const ContractSummary: React.FC = () => {
}

const {
mutation: { mutate, data, error }
mutation: { mutate, data }
} = useTokenOriginate(state.data)

useEffect(() => {
Expand All @@ -107,19 +107,10 @@ export const ContractSummary: React.FC = () => {
type: ActionTypes.CLEAR_CACHE
})
history.push("/creator/success", { address: data.address })
}
}, [data, dispatch, history])

useEffect(() => {
if (error) {
} else if (data && !data.address) {
setIsLoading(false)
openNotification({
message: "Error deploying token... try again later",
variant: "error",
autoHideDuration: 2000
})
}
}, [error, openNotification])
}, [data, dispatch, history])

useEffect(() => {
dispatch({
Expand Down
39 changes: 19 additions & 20 deletions src/services/beacon/hooks/useTezos.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useQueryClient } from "react-query"
import { useCallback, useContext } from "react"
import { MichelCodecPacker, TezosToolkit } from "@taquito/taquito"
import { connectWithBeacon, Network, rpcNodes, TezosActionType } from "services/beacon"
import { connectWithBeacon, createTezos, Network, rpcNodes, TezosActionType } from "services/beacon"
import { TezosContext } from "services/beacon/context"
import { Tzip16Module } from "@taquito/tzip16"
import mixpanel from "mixpanel-browser"
Expand All @@ -17,14 +17,6 @@ type WalletConnectReturn = {
wallet: BeaconWallet | undefined
}

export const initTezosInstance = (network: Network) => {
const newTezos = new TezosToolkit(rpcNodes[network])
newTezos.setPackerProvider(new MichelCodecPacker())
newTezos.addExtension(new Tzip16Module())

return newTezos
}

export const useTezos = (): WalletConnectReturn => {
const {
state: { tezos, network, account, wallet },
Expand All @@ -37,7 +29,7 @@ export const useTezos = (): WalletConnectReturn => {
async (newNetwork?: Network) => {
const { wallet } = await connectWithBeacon(network)

const newTezos: TezosToolkit = initTezosInstance(network || newNetwork)
const newTezos: TezosToolkit = createTezos(network || newNetwork)
newTezos.setProvider({ wallet })

const account = await newTezos.wallet.pkh()
Expand Down Expand Up @@ -74,28 +66,35 @@ export const useTezos = (): WalletConnectReturn => {
}, [dispatch, wallet]),
changeNetwork: async (newNetwork: Network) => {
mixpanel.register({ Network: newNetwork })

localStorage.setItem("homebase:network", newNetwork)

const newTezos: TezosToolkit = createTezos(newNetwork)
if (!("_pkh" in tezos.wallet)) {
const Tezos = new TezosToolkit(rpcNodes[newNetwork])
Tezos.setPackerProvider(new MichelCodecPacker())
Tezos.addExtension(new Tzip16Module())

dispatch({
type: TezosActionType.UPDATE_TEZOS,
payload: {
network: newNetwork,
tezos: Tezos,
account,
tezos: newTezos,
account: "",
wallet: undefined
}
})
} else {
await connect(newNetwork)
const { wallet } = await connectWithBeacon(newNetwork)
newTezos.setProvider({ wallet })
const newAccount = await newTezos.wallet.pkh()

dispatch({
type: TezosActionType.UPDATE_TEZOS,
payload: {
network: newNetwork,
tezos: newTezos,
account: newAccount,
wallet
}
})
}

queryClient.resetQueries()
location.reload()
},
account,
network,
Expand Down
27 changes: 10 additions & 17 deletions src/services/beacon/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,16 @@ export const getTezosNetwork = (): Network => {
return envNetwork
}

let beaconWallet: BeaconWallet

export const createWallet = (network: Network) => {
if (!beaconWallet) {
beaconWallet = new BeaconWallet({
name: "Homebase",
iconUrl: "https://tezostaquito.io/img/favicon.png",
preferredNetwork: network as NetworkType,
walletConnectOptions: {
projectId: "1641355e825aeaa926e843dd38b04f6f", // Project ID can be customised
relayUrl: "wss://relay.walletconnect.com" // WC2 relayUrl can be customised
}
})
}

return beaconWallet
}
export const createWallet = (network: Network) =>
new BeaconWallet({
name: "Homebase",
iconUrl: "https://tezostaquito.io/img/favicon.png",
preferredNetwork: network as NetworkType,
walletConnectOptions: {
projectId: "1641355e825aeaa926e843dd38b04f6f", // Project ID can be customised
relayUrl: "wss://relay.walletconnect.com" // WC2 relayUrl can be customised
}
})

export const createTezos = (network: Network) => {
const tezos = new TezosToolkit(rpcNodes[network])
Expand Down
2 changes: 1 addition & 1 deletion src/services/contracts/baseDAO/hooks/useOriginate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ContractAbstraction, ContractProvider, TezosToolkit, Wallet } from "@ta
import { useMutation, useQueryClient } from "react-query"

import { deployMetadataCarrier } from "services/contracts/metadataCarrier/deploy"
import { initTezosInstance, useTezos } from "services/beacon/hooks/useTezos"
import { useTezos } from "services/beacon/hooks/useTezos"
import { BaseDAO, replacer } from ".."
import { getDAO } from "services/services/dao/services"
import mixpanel from "mixpanel-browser"
Expand Down
69 changes: 40 additions & 29 deletions src/services/contracts/token/hooks/useToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,62 @@ import mixpanel from "mixpanel-browser"
import { TokenContractParams } from "modules/creator/deployment/state/types"
import { getCurrentBlock } from "services/utils/utils"
import { deployTokenContract } from "services/contracts/token"
import { useNotification } from "modules/common/hooks/useNotification"

export const useTokenOriginate = (tokenData: TokenContractParams) => {
const queryClient = useQueryClient()

const { tezos, connect, network, account } = useTezos()
const openNotification = useNotification()

const result = useMutation<ContractAbstraction<ContractProvider | Wallet>, Error, TokenContractParams>(
async ({ tokenDistribution, tokenSettings }) => {
let tezosToolkit = tezos
try {
let tezosToolkit = tezos

if (!account) {
tezosToolkit = await connect()
}
if (!account) {
tezosToolkit = await connect()
}

mixpanel.track("Started Token origination", {
contract: "FA2Token",
tokenName: tokenSettings.name,
tokenSymbol: tokenSettings.symbol
})
mixpanel.track("Started Token origination", {
contract: "FA2Token",
tokenName: tokenSettings.name,
tokenSymbol: tokenSettings.symbol
})

const mutateTokenData: TokenContractParams = {
tokenDistribution,
tokenSettings
}
const mutateTokenData: TokenContractParams = {
tokenDistribution,
tokenSettings
}

const currentBlock = await getCurrentBlock(network)
const currentBlock = await getCurrentBlock(network)

const contract = await deployTokenContract({
...mutateTokenData,
tezos: tezosToolkit,
account,
currentBlock
})
const contract = await deployTokenContract({
...mutateTokenData,
tezos: tezosToolkit,
account,
currentBlock
})

if (!contract) {
throw new Error(`Error deploying ${tokenData.tokenSettings.name} Token`)
}
if (!contract) {
throw new Error(`Error deploying ${tokenData.tokenSettings.name} Token`)
}

mixpanel.track("Completed Token Deployment", {
contract: "FA2Token",
tokenName: tokenSettings.name,
tokenSymbol: tokenSettings.symbol
})
mixpanel.track("Completed Token Deployment", {
contract: "FA2Token",
tokenName: tokenSettings.name,
tokenSymbol: tokenSettings.symbol
})

return contract
return contract
} catch (error) {
openNotification({
message: (error as Error).message,
variant: "error",
autoHideDuration: 2000
})
return error
}
},
{
onSuccess: () => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/contracts/token/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ export const deployTokenContract = async ({

return contract
} catch (e) {
console.error(e)
throw e
}
}
9 changes: 8 additions & 1 deletion src/services/services/lite/lite-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ export const getLiteDAOs = async (network: string) => {
name: dao.name,
decimals: Number(dao.decimals),
standard: dao.tokenType
}
},
ledgers: dao.members.map(member => {
return {
holder: {
address: member
}
}
})
}
return new_dao
})
Expand Down

0 comments on commit 8b9dab6

Please sign in to comment.