Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💥 split contracts into context #195

Open
wants to merge 10 commits into
base: extract-p2p-client
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/Alias.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Alias = ({

useEffect(() => {
aliasesCtx.getAlias(address, defaultAlias).then(setAlias);
}, [address, aliasesCtx]);
}, [address, aliasesCtx, defaultAlias]);

return (
<Copy value={address} text="Copy address" disabled={disabled}>
Expand Down
99 changes: 0 additions & 99 deletions components/Autocomplete.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions components/Banner.tsx

This file was deleted.

6 changes: 5 additions & 1 deletion components/ContractExecution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -528,7 +532,7 @@ function ExecuteForm(
props.onShapeChange(values);
try {
genLambda(
state.contracts[state.currentContract ?? ""]?.version ??
contracts[currentContract]?.version ??
state.currentStorage?.version,
props,
values
Expand Down
129 changes: 0 additions & 129 deletions components/ExecuteContractForm.tsx

This file was deleted.

7 changes: 4 additions & 3 deletions components/FA1_2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -77,7 +78,7 @@ const tokenToOption = (fa1_2Token: fa1_2Token) => {
const FA1_2 = ({ index, remove, children }: props) => {
const state = useAppState();
const { setFieldValue, getFieldProps } = useFormikContext<proposals>();

const currentContract = useCurrentContract();
const [isFetching, setIsFetching] = useState(true);
const [canSeeMore, setCanSeeMore] = useState(true);
const [selectError, setSelectError] = useState<undefined | string>();
Expand All @@ -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);
Expand All @@ -126,7 +127,7 @@ const FA1_2 = ({ index, remove, children }: props) => {

return Promise.resolve(v);
}),
[state.currentContract]
[currentContract]
);

useEffect(() => {
Expand Down
8 changes: 4 additions & 4 deletions components/FA2Transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -94,6 +95,7 @@ const FA2Transfer = ({
const [currentToken, setCurrentToken] = useState<fa2Token | undefined>();
const [options, setOptions] = useState<option[]>([]);
const fetchOffsetRef = useRef(0);
const currentContract = useCurrentContract();

const makeName = (key: string) =>
`transfers.${proposalIndex}.values.${localIndex}.${key}`;
Expand Down Expand Up @@ -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 : ""
}`
)
Expand All @@ -148,7 +148,7 @@ const FA2Transfer = ({
v.filter(token => !toExclude.includes(token.id))
);
}),
[state.currentContract, toExclude]
[currentContract, toExclude]
);

useEffect(() => {
Expand Down
Loading