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

Switch to thirdweb smart account #238

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
1 change: 1 addition & 0 deletions pkgs/frontend/app/components/icon/UserIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const UserIcon = ({ userImageUrl, size = "full" }: UserIconProps) => {
<CommonIcon
imageUrl={userImageUrl}
size={size}
borderRadius="full"
fallbackIconComponent={
<FaCircleUser
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const AssistCreditSend: FC = () => {
return (
<Grid
gridTemplateRows={!receiver ? "auto auto auto 1fr" : "auto auto 1fr auto"}
minH="calc(100vh - 72px)"
minH="calc(100vh - 100px)"
>
<PageHeader
title={
Expand Down
81 changes: 42 additions & 39 deletions pkgs/frontend/app/routes/$treeId_.$hatId_.assign.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC, useState, useEffect, useMemo, useCallback } from "react";
import { Box, Button, Text, HStack } from "@chakra-ui/react";
import { Box, Button, Text, HStack, Grid } from "@chakra-ui/react";
import { useParams } from "@remix-run/react";
import { Address } from "viem";
import { useAddressesByNames } from "hooks/useENS";
Expand Down Expand Up @@ -100,43 +100,46 @@ const AssignRole: FC = () => {
}, [hatId, resolvedAddress, inputValue, mintHat]);

return (
<>
<PageHeader title="役割を割り当てる" />

<HatsListItemParser detailUri={hat?.details} imageUri={hat?.imageUri}>
<RoleDetail />
</HatsListItemParser>

{/* User name or address input */}
<Box mb={4}>
<Text fontSize="sm" fontWeight="medium" mb={1} color="gray.600">
ユーザー名 or ウォレットアドレス
</Text>
<CommonInput
placeholder="ユーザー名 or ウォレットアドレス"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
/>
{resolvedAddress && !isValidEthAddress(inputValue) && (
<HStack mt={1} fontSize="sm" justifyContent="end" color="blue.300">
<FaCircleCheck />
<Text color="gray.500">{abbreviateAddress(resolvedAddress)}</Text>
</HStack>
)}
</Box>

{/* Date input */}
<Box mb={4}>
<Text fontSize="sm" fontWeight="medium" mb={1} color="gray.600">
開始日
</Text>
<CommonInput
value={startDatetime!}
onChange={(e) => {
setStartDatetime(e.target.value);
}}
type="datetime-local"
/>
<Grid gridTemplateRows="1fr auto" minH="calc(100vh - 100px)" pb={5}>
<Box>
<Box mb={5}>
<PageHeader title="役割を割り当てる" />
</Box>
<HatsListItemParser detailUri={hat?.details} imageUri={hat?.imageUri}>
<RoleDetail />
</HatsListItemParser>

{/* User name or address input */}
<Box mb={4}>
<Text fontSize="sm" fontWeight="medium" mb={1} color="gray.600">
ユーザー名 or ウォレットアドレス
</Text>
<CommonInput
placeholder="ユーザー名 or ウォレットアドレス"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
/>
{resolvedAddress && !isValidEthAddress(inputValue) && (
<HStack mt={1} fontSize="sm" justifyContent="end" color="blue.300">
<FaCircleCheck />
<Text color="gray.500">{abbreviateAddress(resolvedAddress)}</Text>
</HStack>
)}
</Box>

{/* Date input */}
<Box mb={4}>
<Text fontSize="sm" fontWeight="medium" mb={1} color="gray.600">
開始日
</Text>
<CommonInput
value={startDatetime!}
onChange={(e) => {
setStartDatetime(e.target.value);
}}
type="datetime-local"
/>
</Box>
</Box>

{/* Assign Button */}
Expand All @@ -151,7 +154,7 @@ const AssignRole: FC = () => {
>
Assign
</CommonButton>
</>
</Grid>
);
};

Expand Down
53 changes: 28 additions & 25 deletions pkgs/frontend/app/routes/$treeId_.splits.new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ const SplitterNew: FC = () => {

const [splitterName, setSplitterName] = useState<string>("");
const _splitterName = useMemo(() => {
return [`${splitterName}.splitter`];
return [`${splitterName}.split`];
}, [splitterName]);
const { addresses } = useAddressesByNames(_splitterName, true);
const availableName = useMemo(() => {
Expand Down Expand Up @@ -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);

Expand All @@ -296,7 +299,7 @@ const SplitterNew: FC = () => {
})
)
);
};
}, [availableName]);

const { setName } = useSetName();
const handleCreateSplitter = async () => {
Expand All @@ -320,7 +323,7 @@ const SplitterNew: FC = () => {

return (
<Grid
minH="calc(100vh - 72px)"
minH="calc(100vh - 100px)"
gridTemplateRows={preview ? "auto auto 1fr auto" : "auto auto 1fr auto"}
>
<PageHeader
Expand Down Expand Up @@ -388,7 +391,7 @@ const SplitterNew: FC = () => {
))}
</List.Root>
</Box>
<BasicButton onClick={handlePreview} mb={5}>
<BasicButton onClick={handlePreview} mb={5} disabled={!availableName}>
プレビュー
</BasicButton>
</>
Expand Down
2 changes: 1 addition & 1 deletion pkgs/frontend/app/routes/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Login: FC = () => {
}, [userName, addresses]);

const handleSubmit = async () => {
if (!wallet) return;
if (!wallet || !availableName) return;

const params: {
name: string;
Expand Down
3 changes: 3 additions & 0 deletions pkgs/frontend/hooks/useFractionToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions pkgs/frontend/hooks/useWallet.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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: {
Expand Down
Loading