From 1dc0490070bf2e83c6592da170af9af27da6e473 Mon Sep 17 00:00:00 2001 From: Joaquim Verges Date: Wed, 29 Jun 2022 15:18:24 -0700 Subject: [PATCH] Gasless publish flow (#216) * gasless publish flow * switch to publishing one at a time for now to support gasless --- components/contract-components/hooks.ts | 7 ++++++- contexts/custom-sdk-context.tsx | 23 +++++++++++++++++++++-- package.json | 2 +- pages/contracts/index.tsx | 7 +++---- pages/contracts/new/custom.tsx | 8 ++++---- pages/contracts/publish.tsx | 9 ++++----- yarn.lock | 18 +++++++++--------- 7 files changed, 48 insertions(+), 26 deletions(-) diff --git a/components/contract-components/hooks.ts b/components/contract-components/hooks.ts index 8fd9328ab..65ee30be2 100644 --- a/components/contract-components/hooks.ts +++ b/components/contract-components/hooks.ts @@ -91,7 +91,12 @@ export function usePublishMutation() { sdk && "getPublisher" in sdk, "sdk is not ready or does not support publishing", ); - return await (await sdk.getPublisher()).publishBatch(uris); + // FIXME - can't call batch here because of a bug with multicall + gasless setup. Looping through the uris and calling publish one by one for now. + const receipts = []; + for (const uri of uris) { + receipts.push(await sdk.getPublisher().publish(uri)); + } + return receipts; }); } diff --git a/contexts/custom-sdk-context.tsx b/contexts/custom-sdk-context.tsx index 7273c3c10..9e480aa91 100644 --- a/contexts/custom-sdk-context.tsx +++ b/contexts/custom-sdk-context.tsx @@ -1,5 +1,5 @@ import { ThirdwebSDKProvider, useSigner } from "@thirdweb-dev/react"; -import { SUPPORTED_CHAIN_ID } from "@thirdweb-dev/sdk"; +import { ChainId, SDKOptions, SUPPORTED_CHAIN_ID } from "@thirdweb-dev/sdk"; import { StorageSingleton, alchemyUrlMap, @@ -9,7 +9,8 @@ import { useProvider } from "wagmi"; export const CustomSDKContext: ComponentWithChildren<{ desiredChainId?: SUPPORTED_CHAIN_ID | -1; -}> = ({ desiredChainId, children }) => { + options?: SDKOptions; +}> = ({ desiredChainId, options, children }) => { const signer = useSigner(); const provider = useProvider(); @@ -29,6 +30,7 @@ export const CustomSDKContext: ComponentWithChildren<{ rpcUrl: alchemyUrlMap[desiredChainId], } : undefined, + ...options, }} storageInterface={StorageSingleton} > @@ -36,3 +38,20 @@ export const CustomSDKContext: ComponentWithChildren<{ ); }; + +export const PublisherSDKContext: ComponentWithChildren = ({ children }) => ( + + {children} + +); diff --git a/package.json b/package.json index 6966d9146..97c50bba0 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@tanstack/react-location": "^3.7.4", "@thirdweb-dev/chain-icons": "^1.0.4", "@thirdweb-dev/react": "^2.4.6", - "@thirdweb-dev/sdk": "^2.3.20", + "@thirdweb-dev/sdk": "^2.3.21-1", "bn.js": "^5.2.0", "color": "^4.0.1", "date-fns": "^2.28.0", diff --git a/pages/contracts/index.tsx b/pages/contracts/index.tsx index d940b377c..1a76cb3f8 100644 --- a/pages/contracts/index.tsx +++ b/pages/contracts/index.tsx @@ -8,12 +8,11 @@ import { Spinner, } from "@chakra-ui/react"; import { useAddress } from "@thirdweb-dev/react"; -import { ChainId } from "@thirdweb-dev/sdk"; import { AppLayout } from "components/app-layouts/app"; import { DeployableContractTable } from "components/contract-components/contract-table"; import { usePublishedContractsQuery } from "components/contract-components/hooks"; import { BuiltinContractMap } from "constants/mappings"; -import { CustomSDKContext } from "contexts/custom-sdk-context"; +import { PublisherSDKContext } from "contexts/custom-sdk-context"; import { useTrack } from "hooks/analytics/useTrack"; import { ReactElement } from "react"; import { IoRefreshSharp } from "react-icons/io5"; @@ -118,9 +117,9 @@ const ContractsHomepageWrapped: React.FC = () => { export default function ContractsHomepage() { return ( - + - + ); } diff --git a/pages/contracts/new/custom.tsx b/pages/contracts/new/custom.tsx index 765d0e60c..4d498a103 100644 --- a/pages/contracts/new/custom.tsx +++ b/pages/contracts/new/custom.tsx @@ -10,11 +10,11 @@ import { Spinner, VStack, } from "@chakra-ui/react"; -import { ChainId, useAddress } from "@thirdweb-dev/react"; +import { useAddress } from "@thirdweb-dev/react"; import { AppLayout } from "components/app-layouts/app"; import { DeployableContractTable } from "components/contract-components/contract-table"; import { usePublishedContractsQuery } from "components/contract-components/hooks"; -import { CustomSDKContext } from "contexts/custom-sdk-context"; +import { PublisherSDKContext } from "contexts/custom-sdk-context"; import { useRouter } from "next/router"; import React, { ReactElement } from "react"; import { FiChevronLeft } from "react-icons/fi"; @@ -134,9 +134,9 @@ function DeployCustomContract() { export default function DeployCustomContractWrapped() { return ( - + - + ); } diff --git a/pages/contracts/publish.tsx b/pages/contracts/publish.tsx index 7cdf7acc0..5ec64d56f 100644 --- a/pages/contracts/publish.tsx +++ b/pages/contracts/publish.tsx @@ -1,12 +1,11 @@ import { Box, Flex, Link } from "@chakra-ui/react"; -import { ChainId } from "@thirdweb-dev/sdk"; import { AppLayout } from "components/app-layouts/app"; import { TransactionButton } from "components/buttons/TransactionButton"; import { DeployableContractTable } from "components/contract-components/contract-table"; import { usePublishMutation } from "components/contract-components/hooks"; import { ContractId } from "components/contract-components/types"; import { UrlMap } from "constants/mappings"; -import { CustomSDKContext } from "contexts/custom-sdk-context"; +import { PublisherSDKContext } from "contexts/custom-sdk-context"; import { useTrack } from "hooks/analytics/useTrack"; import { useTxNotifications } from "hooks/useTxNotifications"; import { useRouter } from "next/router"; @@ -103,7 +102,7 @@ const ContractsPublishPageWrapped: React.FC = () => { { trackEvent({ @@ -146,9 +145,9 @@ const ContractsPublishPageWrapped: React.FC = () => { export default function ContractsPublishPage() { return ( - + - + ); } diff --git a/yarn.lock b/yarn.lock index c85acea92..37b168339 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1853,10 +1853,10 @@ resolved "https://registry.yarnpkg.com/@thirdweb-dev/chain-icons/-/chain-icons-1.0.4.tgz#5b8b88995f71628885d8e72b679fe0631d281036" integrity sha512-veUEsYonSUH3d+OF71eAUnwngDRzaveKbSZqcHNR6MpZExAMYMMnnVW8gsR+S6GLyLGQHahoUnsxqWZZN7Bx2w== -"@thirdweb-dev/contracts@2.3.15-0": - version "2.3.15-0" - resolved "https://registry.yarnpkg.com/@thirdweb-dev/contracts/-/contracts-2.3.15-0.tgz#9ea4aa8500b213356acc1772c18222c8085087c0" - integrity sha512-hm6qK5GSp776ctXV3NeA6jvHHfkolJjTLXQ/ed9gZVBLVD5Bl1ofLRZ30wG3lf8eMMxFoJCEqOsoQlB95M+qOw== +"@thirdweb-dev/contracts@2.4.1": + version "2.4.1" + resolved "https://registry.yarnpkg.com/@thirdweb-dev/contracts/-/contracts-2.4.1.tgz#50a5d5f19fa79aa7607fa64fe6bb28e474403866" + integrity sha512-It1lEQ55Wpad+XlzymlyFeG/j0mBy7qMbACf0615PVoqV1bvQbV1PCaXr4v0toNsDZRemwInINIGUGc27dDT5w== "@thirdweb-dev/react@^2.4.6": version "2.4.6" @@ -1873,12 +1873,12 @@ tiny-invariant "^1.2.0" wagmi "^0.2.28" -"@thirdweb-dev/sdk@^2.3.20": - version "2.3.20" - resolved "https://registry.yarnpkg.com/@thirdweb-dev/sdk/-/sdk-2.3.20.tgz#b096fdedaf156e1ffbeb0ee6bb03a6ab4e899036" - integrity sha512-h0qA7jGaDWMRPCcsBRrEPVRXkgo/2KSYevtW4ql5od8aNvPI+tY+h7wa0CL9bPz5MDbXQGqPe08jPkV7kUSNrw== +"@thirdweb-dev/sdk@^2.3.21-1": + version "2.3.21-1" + resolved "https://registry.yarnpkg.com/@thirdweb-dev/sdk/-/sdk-2.3.21-1.tgz#7860b808c4dc61d935ec95be448a289f64c746fe" + integrity sha512-nqyuGKtzTIWexuUybQiVYqjOCrdqndOLFHBekzNx0syxN2ujGm5jc3mhzu2VNI7NSZSoupm/pEYN9BX0EU/8fQ== dependencies: - "@thirdweb-dev/contracts" "2.3.15-0" + "@thirdweb-dev/contracts" "2.4.1" "@web-std/file" "^3.0.0" cbor "^8.1.0" cross-fetch "^3.1.5"