From 3e67eaa802a43647ec1ddfd6456b55ad1d024871 Mon Sep 17 00:00:00 2001 From: yu23ki14 Date: Thu, 9 Jan 2025 18:12:10 +0900 Subject: [PATCH] use thirdweb smart account --- .../frontend/app/components/icon/UserIcon.tsx | 1 + ...d_.$hatId_.$address_.assistcredit.send.tsx | 2 +- .../app/routes/$treeId_.$hatId_.assign.tsx | 81 ++++++++++--------- .../app/routes/$treeId_.splits.new.tsx | 53 ++++++------ pkgs/frontend/app/routes/signup.tsx | 2 +- pkgs/frontend/hooks/useFractionToken.ts | 3 + pkgs/frontend/hooks/useWallet.ts | 8 +- 7 files changed, 82 insertions(+), 68 deletions(-) diff --git a/pkgs/frontend/app/components/icon/UserIcon.tsx b/pkgs/frontend/app/components/icon/UserIcon.tsx index 89a5c9eb..b0c63fc2 100644 --- a/pkgs/frontend/app/components/icon/UserIcon.tsx +++ b/pkgs/frontend/app/components/icon/UserIcon.tsx @@ -11,6 +11,7 @@ export const UserIcon = ({ userImageUrl, size = "full" }: UserIconProps) => { { return ( { }, [hatId, resolvedAddress, inputValue, mintHat]); return ( - <> - - - - - - - {/* User name or address input */} - - - ユーザー名 or ウォレットアドレス - - setInputValue(e.target.value)} - /> - {resolvedAddress && !isValidEthAddress(inputValue) && ( - - - {abbreviateAddress(resolvedAddress)} - - )} - - - {/* Date input */} - - - 開始日 - - { - setStartDatetime(e.target.value); - }} - type="datetime-local" - /> + + + + + + + + + + {/* User name or address input */} + + + ユーザー名 or ウォレットアドレス + + setInputValue(e.target.value)} + /> + {resolvedAddress && !isValidEthAddress(inputValue) && ( + + + {abbreviateAddress(resolvedAddress)} + + )} + + + {/* Date input */} + + + 開始日 + + { + setStartDatetime(e.target.value); + }} + type="datetime-local" + /> + {/* Assign Button */} @@ -151,7 +154,7 @@ const AssignRole: FC = () => { > Assign - + ); }; diff --git a/pkgs/frontend/app/routes/$treeId_.splits.new.tsx b/pkgs/frontend/app/routes/$treeId_.splits.new.tsx index 435f544d..3f1a5876 100644 --- a/pkgs/frontend/app/routes/$treeId_.splits.new.tsx +++ b/pkgs/frontend/app/routes/$treeId_.splits.new.tsx @@ -215,7 +215,7 @@ const SplitterNew: FC = () => { const [splitterName, setSplitterName] = useState(""); const _splitterName = useMemo(() => { - return [`${splitterName}.splitter`]; + return [`${splitterName}.split`]; }, [splitterName]); const { addresses } = useAddressesByNames(_splitterName, true); const availableName = useMemo(() => { @@ -256,29 +256,32 @@ const SplitterNew: FC = () => { const calcParams = () => { const data = getValues(); - return data.roles.map((role) => { - const [multiplierTop, multiplierBottom] = role.multiplier - ? String(role.multiplier).includes(".") - ? [ - BigInt( - role.multiplier * - 10 ** String(role.multiplier).split(".")[1].length - ), - BigInt(10 ** String(role.multiplier).split(".")[1].length), - ] - : [BigInt(role.multiplier), BigInt(1)] - : [BigInt(1), BigInt(1)]; - - return { - hatId: BigInt(role.hatId), - multiplierTop, - multiplierBottom, - wearers: role.wearers, - }; - }); + return data.roles + .filter((r) => r.active) + .map((role) => { + const [multiplierTop, multiplierBottom] = role.multiplier + ? String(role.multiplier).includes(".") + ? [ + BigInt( + role.multiplier * + 10 ** String(role.multiplier).split(".")[1].length + ), + BigInt(10 ** String(role.multiplier).split(".")[1].length), + ] + : [BigInt(role.multiplier), BigInt(1)] + : [BigInt(1), BigInt(1)]; + + return { + hatId: BigInt(role.hatId), + multiplierTop, + multiplierBottom, + wearers: role.wearers, + }; + }); }; - const handlePreview = async () => { + const handlePreview = useCallback(async () => { + if (!availableName) return; const params = calcParams(); const res = await previewSplits(params); @@ -296,7 +299,7 @@ const SplitterNew: FC = () => { }) ) ); - }; + }, [availableName]); const { setName } = useSetName(); const handleCreateSplitter = async () => { @@ -320,7 +323,7 @@ const SplitterNew: FC = () => { return ( { ))} - + プレビュー diff --git a/pkgs/frontend/app/routes/signup.tsx b/pkgs/frontend/app/routes/signup.tsx index cb999f63..2801bdd3 100644 --- a/pkgs/frontend/app/routes/signup.tsx +++ b/pkgs/frontend/app/routes/signup.tsx @@ -34,7 +34,7 @@ const Login: FC = () => { }, [userName, addresses]); const handleSubmit = async () => { - if (!wallet) return; + if (!wallet || !availableName) return; const params: { name: string; diff --git a/pkgs/frontend/hooks/useFractionToken.ts b/pkgs/frontend/hooks/useFractionToken.ts index 0dc501ea..5b181259 100644 --- a/pkgs/frontend/hooks/useFractionToken.ts +++ b/pkgs/frontend/hooks/useFractionToken.ts @@ -379,6 +379,8 @@ export const useTransferFractionToken = (hatId: bigint, wearer: Address) => { functionName: "safeTransferFrom", args: [wallet.account.address, to, tokenId, amount, "0x"], }); + } catch (_) { + setIsLoading(false); } finally { setIsLoading(false); } @@ -404,6 +406,7 @@ export const useTransferFractionToken = (hatId: bigint, wearer: Address) => { }); } catch (error) { console.error(error); + setIsLoading(false); } finally { await publicClient.waitForTransactionReceipt({ hash: txHash! }); setIsLoading(false); diff --git a/pkgs/frontend/hooks/useWallet.ts b/pkgs/frontend/hooks/useWallet.ts index ae923932..277c896d 100644 --- a/pkgs/frontend/hooks/useWallet.ts +++ b/pkgs/frontend/hooks/useWallet.ts @@ -1,6 +1,9 @@ import { ConnectedWallet, usePrivy, useWallets } from "@privy-io/react-auth"; import { createSmartAccountClient, SmartAccountClient } from "permissionless"; -import { toSimpleSmartAccount } from "permissionless/accounts"; +import { + toSimpleSmartAccount, + toThirdwebSmartAccount, +} from "permissionless/accounts"; import { createPimlicoClient } from "permissionless/clients/pimlico"; import { useCallback, useEffect, useMemo, useState } from "react"; import { @@ -62,7 +65,8 @@ export const useSmartAccountClient = (wallets: ConnectedWallet[]) => { const owner = await embeddedWallet?.getEthereumProvider(); if (!owner) return; - const smartAccount = await toSimpleSmartAccount({ + // We are using thirdweb smart account + const smartAccount = await toThirdwebSmartAccount({ owner, client: publicClient as any, entryPoint: {