Skip to content

Commit

Permalink
Merge branch 'main' into jules/feat/wert
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesGuesnon committed Nov 9, 2023
2 parents 59ccffe + 119ae98 commit 4f2f9ca
Show file tree
Hide file tree
Showing 29 changed files with 2,417 additions and 1,034 deletions.
4 changes: 2 additions & 2 deletions components/FA1_2.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Field, useFormikContext } from "formik";
import { useCallback, useContext, useEffect, useRef, useState } from "react";
import { API_URL, THUMBNAIL_URL } from "../context/config";
import { TZKT_API_URL, THUMBNAIL_URL } from "../context/config";
import { AppStateContext } from "../context/state";
import { debounce, promiseWithTimeout } from "../utils/timeout";
import { proposals } from "../versioned/interface";
Expand Down Expand Up @@ -103,7 +103,7 @@ const FA1_2 = ({ index, remove, children }: props) => {
(value: string, offset: number) =>
promiseWithTimeout(
fetch(
`${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=${state.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 Down
4 changes: 2 additions & 2 deletions components/FA2Transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
useState,
} from "react";
import { v4 as uuidV4 } from "uuid";
import { API_URL, THUMBNAIL_URL } from "../context/config";
import { TZKT_API_URL, THUMBNAIL_URL } from "../context/config";
import { AppStateContext } from "../context/state";
import { debounce } from "../utils/timeout";
import { proposals } from "../versioned/interface";
Expand Down Expand Up @@ -133,7 +133,7 @@ const FA2Transfer = ({
const fetchTokens = useCallback(
(value: string, offset: number) =>
fetch(
`${API_URL}/v1/tokens/balances?account=${
`${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${
!!fa2ContractAddress ? "&token.contract=" + fa2ContractAddress : ""
Expand Down
6 changes: 3 additions & 3 deletions components/ProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const ProposalCard = ({
() =>
content.map(v =>
contentToData(
state.contracts[state.currentContract ?? ""].version ??
state.contracts[state.currentContract ?? ""]?.version ??
state.currentStorage?.version,
v,
walletTokens
Expand Down Expand Up @@ -96,7 +96,7 @@ const ProposalCard = ({
metadataRender
? labelOfProposalContentMetadata(v)
: labelOfProposalContentLambda(
state.contracts[state.currentContract ?? ""].version ??
state.contracts[state.currentContract ?? ""]?.version ??
state.currentStorage?.version,
v
)
Expand All @@ -108,7 +108,7 @@ const ProposalCard = ({
metadataRender
? labelOfProposalContentMetadata(v)
: labelOfProposalContentLambda(
state.contracts[state.currentContract ?? ""].version ??
state.contracts[state.currentContract ?? ""]?.version ??
state.currentStorage?.version,
v
)
Expand Down
6 changes: 4 additions & 2 deletions components/RenderProposalContentLambda.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InfoCircledIcon } from "@radix-ui/react-icons";
import { Parser } from "@taquito/michel-codec";
import { Parser, emitMicheline } from "@taquito/michel-codec";
import BigNumber from "bignumber.js";
import { useState } from "react";
import { LambdaType, parseLambda } from "../context/parseLambda";
Expand Down Expand Up @@ -134,7 +134,9 @@ export const contentToData = (
metadata:
metadata.meta === "No meta supplied" ? undefined : metadata.meta,
amount: !!lambda?.mutez ? `${mutezToTez(lambda.mutez)} Tez` : undefined,
params: metadata.lambda,
params: Array.isArray(metadata.lambda)
? emitMicheline(metadata.lambda)
: metadata.lambda,
};
} else if (type === LambdaType.CONTRACT_EXECUTION) {
data = {
Expand Down
16 changes: 1 addition & 15 deletions components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ import React, {
import fetchVersion from "../context/metadata";
import { AppDispatchContext, AppStateContext } from "../context/state";
import { version } from "../types/display";
import { fetchContract } from "../utils/fetchContract";
import useIsOwner from "../utils/useIsOwner";
import { signers, toStorage } from "../versioned/apis";
import Copy from "./Copy";
import Spinner from "./Spinner";

type selectItemProps = {
name: string | undefined;
Expand Down Expand Up @@ -184,20 +182,8 @@ const Sidebar = ({
</button>
<Select.Root
onValueChange={async payload => {
// State update is done in _app
router.push(`/${payload}/${path?.split("/")[2] ?? ""}`);
dispatch({
type: "setCurrentContract",
payload,
});

const storage = await fetchContract(state.connection, payload);

if (!storage) return;

dispatch({
type: "setCurrentStorage",
payload: { ...storage, address: payload },
});
}}
value={currentContract}
disabled={Object.values(state.contracts).length === 0}
Expand Down
12 changes: 7 additions & 5 deletions components/proposalSignForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function ProposalSignForm({
threshold: number;
id: number;
state: boolean | undefined;
closeModal: () => void;
closeModal: (success: boolean) => void;
walletTokens: walletToken[];
onSuccess?: () => void;
}) {
Expand All @@ -51,7 +51,7 @@ function ProposalSignForm({
() =>
proposal.ui.content.map(v =>
contentToData(
state.contracts[state.currentContract ?? ""].version ??
state.contracts[state.currentContract ?? ""]?.version ??
state.currentStorage?.version,
v,
walletTokens
Expand Down Expand Up @@ -112,7 +112,7 @@ function ProposalSignForm({
<div className="w-full space-x-4">
<button
className="rounded border-2 bg-transparent px-4 py-2 font-medium text-white hover:outline-none"
onClick={closeModal}
onClick={() => closeModal(false)}
>
Close
</button>
Expand Down Expand Up @@ -195,6 +195,7 @@ function ProposalSignForm({
onSubmit={async values => {
setLoading(true);

let success = true;
try {
await sign(
id,
Expand All @@ -206,12 +207,13 @@ function ProposalSignForm({
setResult(true);
setLoading(false);
} catch (e) {
success = false;
console.log("Sign error: ", e);
setResult(false);
}
setLoading(false);
setTimeout(() => {
closeModal();
closeModal(success);
}, MODAL_TIMEOUT);
}}
>
Expand Down Expand Up @@ -329,7 +331,7 @@ function ProposalSignForm({
className="my-2 rounded border-2 bg-transparent p-2 font-medium text-white hover:outline-none"
onClick={e => {
e.preventDefault();
closeModal();
closeModal(false);
}}
>
Cancel
Expand Down
6 changes: 3 additions & 3 deletions components/signersForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
PREFERED_NETWORK,
PROPOSAL_DURATION_WARNING,
} from "../context/config";
import { API_URL } from "../context/config";
import { TZKT_API_URL } from "../context/config";
import {
generateDelegateMichelson,
generateUndelegateMichelson,
Expand Down Expand Up @@ -121,7 +121,7 @@ const SignersForm: FC<{
useEffect(() => {
if (!!state.delegatorAddresses) return;

fetch(`${API_URL}/v1/delegates?select.values=address`)
fetch(`${TZKT_API_URL}/v1/delegates?select.values=address`)
.then(res => res.json())
.then(payload => dispatch({ type: "setDelegatorAddresses", payload }));
}, [state.delegatorAddresses]);
Expand Down Expand Up @@ -443,7 +443,7 @@ const SignersForm: FC<{
else {
try {
const account = await fetch(
`${API_URL}/v1/accounts/${values.bakerAddress}`
`${TZKT_API_URL}/v1/accounts/${values.bakerAddress}`
).then(res => res.json());

if (account.type !== "delegate" || !account.activationLevel)
Expand Down
4 changes: 2 additions & 2 deletions components/topUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React, {
useRef,
useState,
} from "react";
import { API_URL, MODAL_TIMEOUT, THUMBNAIL_URL } from "../context/config";
import { TZKT_API_URL, MODAL_TIMEOUT, THUMBNAIL_URL } from "../context/config";
import fetchVersion from "../context/metadata";
import {
AppDispatchContext,
Expand Down Expand Up @@ -99,7 +99,7 @@ function TopUp(props: {
(value: string, offset: number) =>
promiseWithTimeout(
fetch(
`${API_URL}/v1/tokens/balances?account=${state.address}&offset=${offset}&limit=${FETCH_COUNT}&token.metadata.name.as=*${value}*&balance.ne=0&sort.desc=lastTime&token.standard.in=fa1.2,fa2`
`${TZKT_API_URL}/v1/tokens/balances?account=${state.address}&offset=${offset}&limit=${FETCH_COUNT}&token.metadata.name.as=*${value}*&balance.ne=0&sort.desc=lastTime&token.standard.in=fa1.2,fa2`
)
.catch(e => {
console.log(e);
Expand Down
4 changes: 2 additions & 2 deletions context/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { NetworkType } from "@airgap/beacon-sdk";

export const RPC_URL =
process.env.NEXT_PUBLIC_RPC_URL ?? "https://ghostnet.tezos.marigold.dev/";
export const API_URL =
export const TZKT_API_URL =
process.env.NEXT_PUBLIC_API_URL ?? "https://api.ghostnet.tzkt.io";
export const IPFS = "https://ipfs-proxy.gcp.marigold.dev";
export const IPFS_NODE = "ipfs.gcp.marigold.dev";
export const IPFS_NODE = "gateway.pinata.cloud";
export const PREFERED_NETWORK: NetworkType =
process.env.NEXT_PUBLIC_NETWORK_TYPE === "mainnet"
? NetworkType.MAINNET
Expand Down
12 changes: 6 additions & 6 deletions context/generateLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function generateFA2Michelson(
) {
if (params.length === 0) throw new Error("Empty fa2 params");

if (version === "0.3.1") {
if (version === "0.3.1" || version === "0.3.2") {
return `{
DROP;
NIL operation ;
Expand Down Expand Up @@ -87,7 +87,7 @@ export function generateFA1_2ApproveMichelson(
version: version,
{ spenderAddress, amount, fa1_2Address }: approve
) {
if (version === "0.3.1") {
if (version === "0.3.1" || version === "0.3.2") {
return `{
DROP ;
NIL operation ;
Expand Down Expand Up @@ -118,7 +118,7 @@ export function generateFA1_2TransferMichelson(
version: version,
{ walletAddress, targetAddress, amount, fa1_2Address }: transfer
) {
if (version === "0.3.1") {
if (version === "0.3.1" || version === "0.3.2") {
return `{
DROP ;
NIL operation ;
Expand Down Expand Up @@ -154,7 +154,7 @@ export function generateExecuteContractMichelson(
michelsonEntrypoint = `%${entrypoint}`;
}

if (version === "0.3.1") {
if (version === "0.3.1" || version === "0.3.2") {
return `{
DROP;
NIL operation ;
Expand Down Expand Up @@ -185,7 +185,7 @@ export function generateDelegateMichelson(
version: version,
{ bakerAddress }: { bakerAddress: string }
) {
if (version === "0.3.1") {
if (version === "0.3.1" || version === "0.3.2") {
return `{
DROP ;
NIL operation ;
Expand All @@ -207,7 +207,7 @@ export function generateDelegateMichelson(
}

export function generateUndelegateMichelson(version: version) {
if (version === "0.3.1") {
if (version === "0.3.1" || version === "0.3.2") {
return `{
DROP ;
NIL operation ;
Expand Down
36 changes: 22 additions & 14 deletions context/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "@taquito/taquito";
import { Tzip16ContractAbstraction } from "@taquito/tzip16";
import { version } from "../types/display";
import { API_URL } from "./config";
import { TZKT_API_URL } from "./config";

declare const ABSTRACTION_KEY: unique symbol;
const dispatch: { [key: string]: version } = {
Expand All @@ -17,6 +17,7 @@ const dispatch: { [key: string]: version } = {
"0.1.1": "0.1.1",
"0.3.0": "0.3.0",
"0.3.1": "0.3.1",
"0.3.2": "0.3.2",
};

// Those values are from tzkt api: /v1/contracts
Expand All @@ -32,6 +33,7 @@ const HASHES: { [k in version]: `${typeHash}:${codeHash}` | undefined } = {
"0.1.1": "-483287042:-426350137",
"0.3.0": "-933474574:1358594366",
"0.3.1": "1576695458:46756700",
"0.3.2": "66001562:-1892417854",
"unknown version": undefined,
};

Expand All @@ -42,6 +44,7 @@ const VERSION_HASH: { [k: `${typeHash}:${codeHash}`]: version } = {
[HASHES["0.1.1"]!]: "0.1.1",
[HASHES["0.3.0"]!]: "0.3.0",
[HASHES["0.3.1"]!]: "0.3.1",
[HASHES["0.3.2"]!]: "0.3.2",
};

async function fetchVersion(
Expand All @@ -54,21 +57,26 @@ async function fetchVersion(
}
): Promise<version> {
try {
const version = await metadata
.tzip16()
.getMetadata()
.then(metadata => metadata.metadata.version ?? "unknown version")
.catch(_ =>
fetch(`${API_URL}/v1/contracts?address=${metadata.address}`)
.then(r => r.json())
.then(
([{ typeHash, codeHash }]: {
typeHash: number;
codeHash: number;
}[]) => VERSION_HASH[`${typeHash}:${codeHash}`] ?? "unknown version"
)
let version = await fetch(
`${TZKT_API_URL}/v1/contracts?address=${metadata.address}`
)
.then(r => r.json())
.then(
([{ typeHash, codeHash }]: {
typeHash: number;
codeHash: number;
}[]) => VERSION_HASH[`${typeHash}:${codeHash}`] ?? "unknown version"
);

if (version === "unknown version") {
version = (await metadata
.tzip16()
.getMetadata()
.then(metadata => {
return metadata?.metadata?.version ?? "unknown version";
})) as version;
}

return dispatch[version] ?? "unknown version";
} catch {
return "unknown version";
Expand Down
4 changes: 2 additions & 2 deletions context/metadata_blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let meta = {
name: "TzSafe",
description:
"TzSafe is a multisig wallet aiming at providing better assurance of security and management of ownership than a traditional single-signed wallet",
version: "0.3.0",
version: "0.3.2",
license: {
name: "MIT",
},
Expand All @@ -33,7 +33,7 @@ async function fromIpfs(): Promise<{
const blob = new Blob([bytes], {
type: "application/json;charset=utf-8",
});
formData.append("file", blob, "");
formData.append("file", blob, "tzsafe-metdata.json");
let { cid } = await fetch(`${IPFS}/add`, {
method: "POST",
body: formData,
Expand Down
Loading

0 comments on commit 4f2f9ca

Please sign in to comment.