diff --git a/components/Alias.tsx b/components/Alias.tsx index 7842ab4d..1a2eb60d 100644 --- a/components/Alias.tsx +++ b/components/Alias.tsx @@ -22,7 +22,7 @@ const Alias = ({ useEffect(() => { aliasesCtx.getAlias(address, defaultAlias).then(setAlias); - }, [address, aliasesCtx]); + }, [address, aliasesCtx, defaultAlias]); return ( diff --git a/components/Autocomplete.tsx b/components/Autocomplete.tsx deleted file mode 100644 index 71ecb551..00000000 --- a/components/Autocomplete.tsx +++ /dev/null @@ -1,99 +0,0 @@ -import * as Ariakit from "@ariakit/react"; -import { CheckIcon } from "@radix-ui/react-icons"; -import Spinner from "./Spinner"; - -type props = { - label: string; - onChange: (value: string) => void; - options: (T & { id: string; value: string; label: string })[]; - value: string; - defaultValue?: string; - placeholder?: string; - loading?: boolean; - withSeeMore?: boolean; - selected?: boolean; - onSeeMore?: () => void; - renderOption?: ( - option: T & { id: string; value: string; label: string } - ) => React.ReactNode; -}; - -const Autocomplete = ({ - label, - onChange, - options, - placeholder, - value, - defaultValue, - renderOption, - onSeeMore, - loading = false, - withSeeMore = false, - selected = false, -}: props) => { - const combobox = Ariakit.useComboboxStore({ - gutter: 0, - sameWidth: true, - value, - defaultValue, - setValue(value) { - onChange(value); - }, - }); - - return ( -
- - - {loading ? ( -
- -
- ) : ( - options - .filter(({ label }) => - label.toLowerCase().includes(value.toLowerCase()) - ) - .map(v => ( - - {renderOption?.(v) ?? v.label} - - )) - )} - {withSeeMore && ( -
- -
- )} -
-
- ); -}; - -export default Autocomplete; diff --git a/components/Banner.tsx b/components/Banner.tsx deleted file mode 100644 index c1761edd..00000000 --- a/components/Banner.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { Cross1Icon } from "@radix-ui/react-icons"; -import { useState } from "react"; - -type props = { - children: React.ReactNode; -}; - -const Banner = ({ children }: props) => { - const [hasBanner, setHasBanner] = useState(true); - - return hasBanner ? ( -
-
{children}
- -
- ) : null; -}; - -export default Banner; diff --git a/components/ContractExecution.tsx b/components/ContractExecution.tsx index ff66f090..fbbfcc21 100644 --- a/components/ContractExecution.tsx +++ b/components/ContractExecution.tsx @@ -8,8 +8,10 @@ import { useFormikContext, } from "formik"; import React, { useEffect } from "react"; +import { useContracts } from "../context/contracts"; import { useAppState } from "../context/state"; import { useTezosToolkit } from "../context/tezos-toolkit"; +import useCurrentContract from "../hooks/useCurrentContract"; import { parseContract, genLambda, @@ -489,6 +491,8 @@ function ExecuteForm( const state = useAppState(); const { tezos } = useTezosToolkit(); + const { contracts } = useContracts(); + const currentContract = useCurrentContract(); const address = props.address; const setLoading = props.setLoading; @@ -528,7 +532,7 @@ function ExecuteForm( props.onShapeChange(values); try { genLambda( - state.contracts[state.currentContract ?? ""]?.version ?? + contracts[currentContract]?.version ?? state.currentStorage?.version, props, values diff --git a/components/ExecuteContractForm.tsx b/components/ExecuteContractForm.tsx deleted file mode 100644 index e0b660b1..00000000 --- a/components/ExecuteContractForm.tsx +++ /dev/null @@ -1,129 +0,0 @@ -import { Field, useFormikContext } from "formik"; -import React, { useCallback, useEffect, useRef, useState } from "react"; -import { useWallet } from "../context/wallet"; -import { tezToMutez } from "../utils/tez"; -import ExecuteForm from "./ContractExecution"; -import ContractLoader from "./contractLoader"; -import renderError from "./formUtils"; -import { state, Basic } from "./transferForm"; - -export function ExecuteContractForm( - props: React.PropsWithoutRef<{ - setField: (lambda: string, metadata: string) => void; - getFieldProps: (name: string) => { value: string }; - id: number; - defaultState?: state; - onReset: () => void; - onChange: (state: state) => void; - }> -) { - const { submitCount, setFieldValue } = useFormikContext(); - const submitCountRef = useRef(submitCount); - const { userAddress } = useWallet(); - - const [state, setState] = useState( - () => props.defaultState ?? { address: "", amount: 0, shape: {} } - ); - const [loading, setLoading] = useState(false); - const [error, setError] = useState(""); - - const setLoader = useCallback((x: boolean) => setLoading(x), []); - - useEffect(() => { - props.onChange(state); - }, [state, props.onChange]); - - if (loading) { - return ( -
- -
- ); - } - - return ( -
-

- - #{(props.id + 1).toString().padStart(2, "0")} - - Execute Contract -

- setState({ ...x, shape: {} })} - onAmountChange={amount => { - setState({ ...state, amount: tezToMutez(Number(amount)) }); - setFieldValue(`transfers.${props.id}.amount`, amount); - }} - onAddressChange={address => { - setState({ ...state, address }); - }} - withContinue={!userAddress} - address={userAddress} - defaultValues={{ - amount: undefined, - address: undefined, - }} - /> - {!!userAddress && ( - { - setState(v => ({ - ...v, - shape: { ...v.shape, init: shape }, - })); - }} - setState={shape => { - setState(v => ({ ...v, shape })); - }} - reset={() => setState({ address: "", amount: 0, shape: {} })} - address={userAddress} - amount={state.amount} - setField={(lambda: string, metadata: string) => { - props.setField(lambda, metadata); - }} - onReset={() => { - setState({ address: "", amount: 0, shape: {} }); - props.onReset(); - }} - /> - )} - { - // This is a tricky way to detect when the submition happened - // We want this message to show only on submit, not on every change - if (!!v) { - submitCountRef.current = submitCount; - setError(""); - return; - } - - if (submitCountRef.current === submitCount - 1) { - setError("Please fill contract"); - submitCountRef.current += 1; - } - - // Returning a value to prevent submition - return true; - }} - /> - { - if (!!v) return; - - // Returning a value to prevent submition - return true; - }} - /> - {!!error && renderError(error)} -
- ); -} diff --git a/components/FA1_2.tsx b/components/FA1_2.tsx index db73da2d..cb3ce71e 100644 --- a/components/FA1_2.tsx +++ b/components/FA1_2.tsx @@ -2,6 +2,7 @@ import { Field, useFormikContext } from "formik"; import { useCallback, useEffect, useRef, useState } from "react"; import { TZKT_API_URL, THUMBNAIL_URL } from "../context/config"; import { useAppState } from "../context/state"; +import useCurrentContract from "../hooks/useCurrentContract"; import { debounce, promiseWithTimeout } from "../utils/timeout"; import { proposals } from "../versioned/interface"; import ErrorMessage from "./ErrorMessage"; @@ -77,7 +78,7 @@ const tokenToOption = (fa1_2Token: fa1_2Token) => { const FA1_2 = ({ index, remove, children }: props) => { const state = useAppState(); const { setFieldValue, getFieldProps } = useFormikContext(); - + const currentContract = useCurrentContract(); const [isFetching, setIsFetching] = useState(true); const [canSeeMore, setCanSeeMore] = useState(true); const [selectError, setSelectError] = useState(); @@ -103,7 +104,7 @@ const FA1_2 = ({ index, remove, children }: props) => { (value: string, offset: number) => promiseWithTimeout( fetch( - `${TZKT_API_URL}/v1/tokens/balances?account=${state.currentContract}&offset=${offset}&limit=${FETCH_COUNT}&token.metadata.name.as=*${value}*&balance.ne=0&sort.desc=lastTime&token.standard.eq=fa1.2` + `${TZKT_API_URL}/v1/tokens/balances?account=${currentContract}&offset=${offset}&limit=${FETCH_COUNT}&token.metadata.name.as=*${value}*&balance.ne=0&sort.desc=lastTime&token.standard.eq=fa1.2` ) .catch(e => { console.log(e); @@ -126,7 +127,7 @@ const FA1_2 = ({ index, remove, children }: props) => { return Promise.resolve(v); }), - [state.currentContract] + [currentContract] ); useEffect(() => { diff --git a/components/FA2Transfer.tsx b/components/FA2Transfer.tsx index 4fcc1bd7..95b4a32c 100644 --- a/components/FA2Transfer.tsx +++ b/components/FA2Transfer.tsx @@ -6,6 +6,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { v4 as uuidV4 } from "uuid"; import { TZKT_API_URL, THUMBNAIL_URL } from "../context/config"; import { useAppState } from "../context/state"; +import useCurrentContract from "../hooks/useCurrentContract"; import { debounce } from "../utils/timeout"; import { proposals } from "../versioned/interface"; import ErrorMessage from "./ErrorMessage"; @@ -94,6 +95,7 @@ const FA2Transfer = ({ const [currentToken, setCurrentToken] = useState(); const [options, setOptions] = useState([]); const fetchOffsetRef = useRef(0); + const currentContract = useCurrentContract(); const makeName = (key: string) => `transfers.${proposalIndex}.values.${localIndex}.${key}`; @@ -126,9 +128,7 @@ const FA2Transfer = ({ const fetchTokens = useCallback( (value: string, offset: number) => fetch( - `${TZKT_API_URL}/v1/tokens/balances?account=${ - state.currentContract - }&offset=${offset}&limit=${FETCH_COUNT}&token.metadata.name.as=*${value}*&balance.ne=0&sort.desc=lastTime&token.standard.eq=fa2${ + `${TZKT_API_URL}/v1/tokens/balances?account=${currentContract}&offset=${offset}&limit=${FETCH_COUNT}&token.metadata.name.as=*${value}*&balance.ne=0&sort.desc=lastTime&token.standard.eq=fa2${ !!fa2ContractAddress ? "&token.contract=" + fa2ContractAddress : "" }` ) @@ -148,7 +148,7 @@ const FA2Transfer = ({ v.filter(token => !toExclude.includes(token.id)) ); }), - [state.currentContract, toExclude] + [currentContract, toExclude] ); useEffect(() => { diff --git a/components/Layout.tsx b/components/Layout.tsx index c28ae6da..d0efa657 100644 --- a/components/Layout.tsx +++ b/components/Layout.tsx @@ -1,16 +1,13 @@ -import { NetworkType } from "@airgap/beacon-sdk"; import { ArrowRightIcon } from "@radix-ui/react-icons"; import { validateAddress, ValidationResult } from "@taquito/utils"; import { AppProps } from "next/app"; import { usePathname } from "next/navigation"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; -import { PREFERED_NETWORK } from "../context/config"; -import { useAppDispatch, useAppState } from "../context/state"; +import { useContracts } from "../context/contracts"; +import { useAppState } from "../context/state"; import { useTezosToolkit } from "../context/tezos-toolkit"; -import { contractStorage } from "../types/Proposal0_3_1"; -import { fetchContract } from "../utils/fetchContract"; -import Banner from "./Banner"; +import useCurrentContract from "../hooks/useCurrentContract"; import LoginModal from "./LoginModal"; import PoeModal from "./PoeModal"; import Sidebar from "./Sidebar"; @@ -23,16 +20,17 @@ export default function Layout({ pageProps, }: Pick) { const state = useAppState(); - const dispatch = useAppDispatch(); const { tezos } = useTezosToolkit(); const [data, setData] = useState(); const [hasSidebar, setHasSidebar] = useState(false); - const [isFetching, setIsFetching] = useState(true); + const [isFetching, setIsFetching] = useState(false); const router = useRouter(); const path = usePathname(); + const { contracts, fetchContract } = useContracts(); + const currentContract = useCurrentContract(); const isSidebarHidden = - Object.values(state.contracts).length === 0 && + Object.values(contracts).length === 0 && (path === "/" || path === "/new-wallet" || path === "/import-wallet" || @@ -49,10 +47,10 @@ export default function Layout({ setData(queryParams.get("data")!); } - const contracts = Object.keys(state.contracts); + const contractsAddress = Object.keys(contracts); - if ((path === "/" || path === "") && contracts.length > 0) { - const contract = contracts[0]; + if ((path === "/" || path === "") && contractsAddress.length > 0) { + const contract = contractsAddress[0]; router.replace(`/${contract}/dashboard`); return; @@ -62,90 +60,24 @@ export default function Layout({ } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [state.currentContract, path, state.contracts]); + }, [currentContract, path, contracts]); useEffect(() => { (async () => { - if ( - router.pathname.includes("[walletAddress]") && - !router.query.walletAddress - ) - return; - - if ( - !router.query.walletAddress || - Array.isArray(router.query.walletAddress) || - (router.query.walletAddress === state.currentContract && - !!state.currentStorage) - ) { - setIsFetching(false); - return; - } - - if (!!state.contracts[router.query.walletAddress]) { - dispatch({ - type: "setCurrentContract", - payload: router.query.walletAddress, - }); - setIsFetching(false); - } - - if ( - validateAddress(router.query.walletAddress) !== ValidationResult.VALID - ) { - setIsFetching(false); - router.replace( - `/invalid-contract?address=${router.query.walletAddress}` - ); - return; - } - - if (state.currentStorage?.address === router.query.walletAddress) { + if (validateAddress(currentContract) !== ValidationResult.VALID) { setIsFetching(false); + router.replace(`/invalid-contract?address=${currentContract}`); return; } - - try { - const storage = await fetchContract(tezos, router.query.walletAddress); - - if (!storage) { + setIsFetching(true); + fetchContract(currentContract) + .then(() => setIsFetching(false)) + .catch(() => { setIsFetching(false); - router.replace( - `/invalid-contract?address=${router.query.walletAddress}` - ); - return; - } - - storage.address = router.query.walletAddress; - - dispatch({ - type: "setCurrentStorage", - payload: storage as contractStorage & { address: string }, - }); - - dispatch({ - type: "setCurrentContract", - payload: router.query.walletAddress, + router.replace(`/invalid-contract?address=${currentContract}`); }); - - setIsFetching(false); - } catch (e) { - setIsFetching(false); - - router.replace( - `/invalid-contract?address=${router.query.walletAddress}` - ); - } })(); - }, [ - router.query.walletAddress, - state.currentContract, - dispatch, - router, - state.currentStorage, - tezos, - state.contracts, - ]); + }, [currentContract, state.currentStorage, tezos]); useEffect(() => { setHasSidebar(false); @@ -163,14 +95,7 @@ export default function Layout({ /> )} - - Make sure the URL is - {PREFERED_NETWORK === NetworkType.MAINNET - ? "tzsafe.marigold.dev" - : PREFERED_NETWORK === NetworkType.GHOSTNET - ? "ghostnet.tzsafe.marigold.dev" - : "a valid URL"} - + {isSidebarHidden ? null : ( @@ -181,11 +106,7 @@ export default function Layout({ /> )} -
+
- {userAddress == null ? ( + {!userAddress ? (
@@ -139,7 +140,7 @@ const NavBar = (_: React.PropsWithChildren) => {
- {state && state.contracts && ( + {contracts && (
{!userAddress ? (
diff --git a/components/proposalSignForm.tsx b/components/proposalSignForm.tsx index d1ce887b..71e436d0 100644 --- a/components/proposalSignForm.tsx +++ b/components/proposalSignForm.tsx @@ -7,10 +7,12 @@ import { useRouter } from "next/router"; import React, { useContext, useState, useMemo } from "react"; import { MODAL_TIMEOUT, PREFERED_NETWORK } from "../context/config"; import { PROPOSAL_DURATION_WARNING } from "../context/config"; -import { AppStateContext, useAppState } from "../context/state"; +import { useContracts } from "../context/contracts"; +import { useAppState } from "../context/state"; import { TezosToolkitContext } from "../context/tezos-toolkit"; import { useWallet } from "../context/wallet"; import { CustomView, customViewMatchers } from "../dapps"; +import useCurrentContract from "../hooks/useCurrentContract"; import { version, proposal } from "../types/display"; import { canExecute, canReject } from "../utils/proposals"; import { walletToken } from "../utils/useWalletTokens"; @@ -46,7 +48,8 @@ function ProposalSignForm({ onSuccess?: () => void; }) { const state = useAppState(); - const currentContract = state.currentContract ?? ""; + const { contracts } = useContracts(); + const currentContract = useCurrentContract(); const { userAddress } = useWallet(); @@ -62,8 +65,7 @@ function ProposalSignForm({ const { rows, dapp } = useMemo(() => { const rows = proposal.ui.content.map(v => contentToData( - state.contracts[currentContract]?.version ?? - state.currentStorage?.version, + contracts[currentContract]?.version ?? state.currentStorage?.version, v, walletTokens ) @@ -80,12 +82,7 @@ function ProposalSignForm({ console.log("Failed to parse dapp:", e); } return { rows, dapp }; - }, [ - proposal.ui.content, - state.currentContract, - state.contracts, - state.currentStorage, - ]); + }, [proposal.ui.content, currentContract, contracts, state.currentStorage]); async function sign( proposal: number, @@ -195,7 +192,7 @@ function ProposalSignForm({ } const allSigners = signers( - state.contracts[currentContract] ?? state.currentStorage + contracts[currentContract] ?? state.currentStorage ); const signatures = proposal.ui.signatures.filter(({ signer }) => diff --git a/components/proposals.tsx b/components/proposals.tsx deleted file mode 100644 index 174d616d..00000000 --- a/components/proposals.tsx +++ /dev/null @@ -1,396 +0,0 @@ -import { FC, useState } from "react"; -import { tezosState, useAppState } from "../context/state"; -import { useWallet } from "../context/wallet"; -import { ContractStorage } from "../types/app"; -import { - mutezTransfer, - proposal, - proposalContent, - status, -} from "../types/display"; -import { adaptiveTime, countdown } from "../utils/adaptiveTime"; -import { mutezToTez } from "../utils/tez"; -import { signers } from "../versioned/apis"; -import ContractLoader from "./contractLoader"; - -function getClass(x: number, active: number): string { - return x == active - ? "inline-block p-4 w-full md:w-full text-left md:text-center break-normal rounded-t-lg border-b-2 text-md md:text-2xl uppercase border-primary text-white" - : "inline-block p-4 w-full md:w-full text-left md:text-center text-md md:text-2xl uppercase rounded-t-lg border-b-2 border-gray-100 hover:text-zinc-600 hover:border-primary text-white "; -} -const Proposals: FC<{ - proposals: [number, { og: any; ui: proposal }][]; - address: string; - contract: ContractStorage; - transfers: mutezTransfer[]; - setCloseModal: (_: number, arg: boolean | undefined) => void; -}> = ({ proposals, address, contract, setCloseModal, transfers }) => { - const { userAddress } = useWallet(); - let [currentTab, setCurrentTab] = useState(0); - let state = useAppState(); - - return ( -
-

Proposals

-
-
    -
  • - -
  • -
  • - -
  • -
-
-
-
    - {proposals && - proposals.length > 0 && - [ - ...proposals.filter( - ([_, proposal]) => "Proposing" === proposal.ui.status - ), - ] - .sort((a, b) => b[0] - a[0]) - .map(x => { - return ( - - setCloseModal(x[0], arg) - } - key={JSON.stringify(x[1])} - prop={x[1]} - address={address} - signable={ - !!userAddress && - !!!x[1].ui.signatures.find( - x => x.signer == userAddress - ) && - true - } - /> - ); - })} -
-
    - {proposals && - proposals.length > 0 && - [ - ...proposals.filter( - ([_, proposal]) => !("Proposing" === proposal.ui.status) - ), - ] - .concat( - transfers.map( - x => [-1, { ui: { timestamp: x.timestamp }, ...x }] as any - ) - ) - .sort( - (a, b) => - Number(Date.parse(b[1].ui.timestamp).toString(10)) - - Number(Date.parse(a[1].ui.timestamp).toString(10)) - ) - .map(x => { - return x[0] == -1 ? ( - - ) : ( - - ); - })} -
-
-
- ); -}; -const Transfer: FC<{ - prop: mutezTransfer; - address: string; -}> = ({ prop, address }) => { - let state = useAppState(); - - return ( -
  • -
    -

    - Transaction: received Tez{" "} -

    -
    -
    -

    Sender:

    -

    - {state.aliases[prop.sender.address] || prop.sender.address} -

    -
    - {prop.initiator && ( -
    -

    Initiator:

    -

    - {state.aliases[prop.initiator.address] || prop.initiator.address} -

    -
    - )} -
    -

    Target:

    -

    - {state.aliases[address] || address} -

    -
    -
    -

    Amount:

    -

    - {mutezToTez(prop.amount)} -

    -
    -
    -

    Timestamp:

    -

    - {prop.timestamp} -

    -
    -
  • - ); -}; -function getState(t: proposal): status { - return t.status; -} -const Card: FC<{ - prop: { og: any; ui: proposal }; - address: string; - id: number; - signable: boolean; - contract: ContractStorage; - setCloseModal?: (arg: boolean | undefined) => void; -}> = ({ contract, prop, address, id, signable, setCloseModal = () => {} }) => { - let state = useAppState(); - let [loading, setLoading] = useState(false); - const { userAddress } = useWallet(); - function resolvable( - signatures: { signer: string; result: boolean }[] - ): boolean { - let pro = - signatures.filter(x => x.result).length >= contract.threshold.toNumber(); - let against = - signatures.filter(x => !x.result).length > contract.threshold.toNumber(); - return pro || against; - } - return ( -
  • -
    -

    Status:

    -

    - {getState(prop.ui)} -

    -
    - {"effective_period" in contract && ( -
    -

    Expires in:

    -

    - {countdown(contract.effective_period, prop.ui.timestamp)} -

    -
    - )} -
    -

    Proposed by:

    -

    - {state.aliases[prop.ui.author] || prop.ui.author} -

    -
    - - {("Executed" === prop.ui.status || "Rejected" === prop.ui.status) && ( -
    -

    Signed By:

    -

    - [ {[...prop.ui.signatures.keys()].join(", ")} ] -

    -
    - )} - {"Proposing" === prop.ui.status && ( -
    -

    - Waiting for signatures from:{" "} -

    -

    - [ - {signers(contract) - .filter(x => !!!prop.ui.signatures.find(p => x === p.signer)) - .map(x => state.aliases[x] || x) - .join(", ")}{" "} - ] -

    -
    - )} -
    -

    Transactions:

    -

    - [ - {prop.ui.content - .map(x => `${renderContent(x, state, address, contract)}`) - .join(", ")}{" "} - ] -

    -
    -
    - - {userAddress && - signers(contract).includes(userAddress) && - signable && ( - - )} - {userAddress && - signers(contract).includes(userAddress) && - resolvable(prop.ui.signatures) && - "Executed" !== prop.ui.status && ( - - )} - {userAddress && - signers(contract).includes(userAddress) && - signable && ( - - )} - {userAddress && - signers(contract).includes(userAddress) && - !resolvable(prop.ui.signatures) && - !signable && - "Proposing" === prop.ui.status && ( -

    - Waiting for signatures of other owners -

    - )} -
    -
    -
  • - ); -}; - -function renderContent( - x: proposalContent, - state: tezosState, - address: string, - contract: ContractStorage -): string { - if ("transfer" in x) { - return `${mutezToTez(x.transfer.amount)} Tez to ${ - state.aliases[x.transfer.destination] || x.transfer.destination - }`; - } - if ("executeLambda" in x) { - return `Execute Lambda(${x.executeLambda.metadata})`; - } - if ("execute" in x) { - return `Execute (${x.execute})`; - } - if ("adjustEffectivePeriod" in x) { - return `Adjust effective period: (${adaptiveTime( - x.adjustEffectivePeriod.toString() - )})`; - } - if ("addOwners" in x) { - return `Add [${x.addOwners.join(", ")}] to validators`; - } - if ("removeOwners" in x) { - return `Remove [${x.removeOwners.join(", ")}] from validators`; - } - if ("changeThreshold" in x) { - return `Change threshold from ${contract.threshold} to ${x.changeThreshold}`; - } - if ("add_or_update_metadata" in x) { - return `Updata metadata`; - } - return "Not supported"; -} -export default Proposals; diff --git a/components/signersForm.tsx b/components/signersForm.tsx index d48d0e96..b5506eff 100644 --- a/components/signersForm.tsx +++ b/components/signersForm.tsx @@ -11,12 +11,14 @@ import { } from "formik"; import { useRouter } from "next/router"; import { FC, useContext, useEffect, useMemo, useRef, useState } from "react"; +import { useAliases } from "../context/aliases"; import { MODAL_TIMEOUT, PREFERED_NETWORK, PROPOSAL_DURATION_WARNING, } from "../context/config"; import { TZKT_API_URL } from "../context/config"; +import { useContracts } from "../context/contracts"; import { generateDelegateMichelson, generateUndelegateMichelson, @@ -24,6 +26,7 @@ import { import { useAppDispatch, useAppState } from "../context/state"; import { TezosToolkitContext } from "../context/tezos-toolkit"; import { useWallet } from "../context/wallet"; +import useCurrentContract from "../hooks/useCurrentContract"; import { ContractStorage } from "../types/app"; import { durationOfDaysHoursMinutes, @@ -90,9 +93,12 @@ const SignersForm: FC<{ const state = useAppState(); const dispatch = useAppDispatch(); const { userAddress } = useWallet(); + const { updateAliases, addressBook } = useAliases(); const { tezos } = useContext(TezosToolkitContext); const router = useRouter(); const bakerAddressRef = useRef(null); + const { contracts } = useContracts(); + const currentContract = useCurrentContract(); const [loading, setLoading] = useState(false); const [timeoutAndHash, setTimeoutAndHash] = useState([false, ""]); @@ -143,7 +149,7 @@ const SignersForm: FC<{ : signers(props.contract) ).map((x: string) => ({ address: x, - name: state.aliases[x] || "", + name: addressBook[x] || "", })), days: duration?.days?.toString(), hours: duration?.hours?.toString(), @@ -166,7 +172,7 @@ const SignersForm: FC<{ if (!props.contract) return []; const version = - state.contracts[state.currentContract ?? ""]?.version ?? + contracts[currentContract ?? ""]?.version ?? state.currentStorage?.version; const initialSigners = new Set( @@ -276,7 +282,7 @@ const SignersForm: FC<{