Skip to content

Commit 0d6c166

Browse files
authored
Merge pull request #893 from dacadeorg/ft/change-walletConnect-package
Ft/change wallet connect package
2 parents c4d8ca1 + 9c876f2 commit 0d6c166

File tree

15 files changed

+10821
-10312
lines changed

15 files changed

+10821
-10312
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@types/react": "18.0.28",
2222
"@types/react-dom": "18.0.11",
2323
"@typescript-eslint/eslint-plugin": "^6.3.0",
24-
"@walletconnect/web3-provider": "^1.8.0",
24+
"@web3modal/wagmi": "^3.2.0",
2525
"axios": "^1.3.4",
2626
"classnames": "^2.3.2",
2727
"date-fns": "^2.29.3",
@@ -75,6 +75,8 @@
7575
"unified": "^10.1.2",
7676
"unist-util-visit": "^2.0.0",
7777
"use-onclickoutside": "^0.4.1",
78+
"viem": "^1.18.1",
79+
"wagmi": "^1.4.5",
7880
"web3": "^1.10.0",
7981
"web3modal": "^1.9.12"
8082
},

public/locales/bg/common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@
276276
"profile.wallet.payout.request": "Payout request",
277277
"profile.wallet.payout.amount": "Amount",
278278
"profile.wallet.payout.send": "Send request",
279+
"profile.achievement.mintable": "Монетен",
280+
"profile.achievement.mintable-na": "Монетен N/A",
279281
"faq.title": "FAQ",
280282
"faq.subtitle": "If you have any additional questions or need help visit our ",
281283
"faq.discord": "Discord server.",

public/locales/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@
305305
"profile.achievement.token-id": "Token id",
306306
"profile.achievement.ipfs-metadata": "Metadata",
307307
"profile.achievement.mintable": "Mintable",
308+
"profile.achievement.mintable-na": "Mintable N/A",
308309
"profile.connect.wallet.button": "Connect wallet",
309310
"faq.title": "FAQ",
310311
"faq.subtitle": "If you have any additional questions or need help visit our ",

public/locales/es/common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@
277277
"profile.wallet.payout.request": "Solicite su pago",
278278
"profile.wallet.payout.amount": "Cantidad",
279279
"profile.wallet.payout.send": "Envíe una solicitud",
280+
"profile.achievement.mintable": "Acuñable",
281+
"profile.achievement.mintable-na": "Acuñable N/A",
280282
"faq.title": "FAQ",
281283
"faq.subtitle": "Si tiene más preguntas o necesita ayuda visite nuestro ",
282284
"faq.discord": "servidor de Discord.",

public/locales/hr/common.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@
276276
"profile.wallet.payout.request": "Payout request",
277277
"profile.wallet.payout.amount": "Amount",
278278
"profile.wallet.payout.send": "Send request",
279+
"profile.achievement.mintable": "Mintable",
280+
"profile.achievement.mintable-na": "Mintable N/A",
279281
"faq.title": "FAQ",
280282
"faq.subtitle": "If you have any additional questions or need help visit our ",
281283
"faq.discord": "Discord server.",

src/components/cards/Achievement.tsx

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/* eslint-disable @next/next/no-img-element */
2-
import { ReactElement } from "react";
2+
import { ReactElement, useMemo } from "react";
33

44
import Link from "next/link";
55
import { Certificate } from "@/types/certificate";
6+
import { useTranslation } from "next-i18next";
7+
import classNames from "classnames";
8+
import Checkmark from "@/icons/checkMarkIcon.svg";
69

710
/**
811
* Achievement card props interface
@@ -16,9 +19,22 @@ interface AchievementCardProps {
1619
minting?: boolean;
1720
}
1821

19-
export default function AchievementCard({ data }: AchievementCardProps): ReactElement {
20-
21-
22+
export default function AchievementCard({ data, minting }: AchievementCardProps): ReactElement {
23+
const { t } = useTranslation();
24+
const mintable = useMemo(() => {
25+
return data?.community?.can_mint_certificates;
26+
}, [data]);
27+
28+
const minted = useMemo(() => {
29+
return !!data?.minting?.tx && mintable;
30+
}, [data, mintable]);
31+
32+
const badgeText = useMemo(() => {
33+
if (!mintable) {
34+
return t("profile.achievement.mintable-na");
35+
}
36+
return !minted && !minting ? t("profile.achievement.mintable") : "NFT";
37+
}, [mintable, minted, t]);
2238

2339
const isNotCertificateIcon: boolean = !!data?.metadata?.image?.includes("/img/certificates/");
2440

@@ -28,26 +44,28 @@ export default function AchievementCard({ data }: AchievementCardProps): ReactEl
2844
<div className="flex flex-col h-full">
2945
<div className="flex-grow w-full mx-auto text-left px-7">
3046
<div className="min-h-2xs">
31-
<div
32-
className={`mx-auto relative rounded-full mb-5 ${!isNotCertificateIcon ? "w-20 h-20" : ""}`}
33-
style={{ backgroundColor: isNotCertificateIcon ? data?.community.colors?.cover?.background || data?.community.colors.primary : "" }}
34-
>
35-
<img src={data?.metadata?.image} alt="achievement" />
36-
</div>
47+
<div
48+
className={`mx-auto relative rounded-full mb-5 ${!isNotCertificateIcon ? "w-20 h-20" : ""}`}
49+
style={{ backgroundColor: isNotCertificateIcon ? data?.community.colors?.cover?.background || data?.community.colors.primary : "" }}
50+
>
51+
<img src={data?.metadata?.image} alt="achievement" />
52+
</div>
3753
</div>
38-
39-
<p className="text-sm font-medium text-center pb-5">{data?.metadata?.name}</p>
54+
55+
<p className="text-sm font-medium text-center pb-5">{data?.metadata?.name}</p>
4056
</div>
4157

42-
{/* <div
43-
className={classNames("rounded-b-3.5xl border-t border-solid mt-4 py-4 bort flex flex-none justify-center items-center space-x-1", {
44-
"bg-gray-100": minted,
45-
invisible: !mintable,
46-
})}
47-
>
48-
{minted && <Checkmark />}
49-
<p className="text-base font-normal text-center">{badgeText}</p>
50-
</div> */}
58+
{minting && (
59+
<div
60+
className={classNames("rounded-b-3.5xl border-t border-solid mt-4 py-4 bort flex flex-none justify-center items-center space-x-1", {
61+
"bg-gray-100": minted,
62+
invisible: !mintable,
63+
})}
64+
>
65+
{minted && <Checkmark />}
66+
<p className="text-base font-normal text-center">{badgeText}</p>
67+
</div>
68+
)}
5169
</div>
5270
</Link>
5371
</div>

src/components/sections/profile/modals/EditAddress/_partials/Form.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { useEffect, useMemo } from "react";
77
import { useForm } from "react-hook-form";
88
import { useTranslation } from "react-i18next";
99
import EditAdressFooter from "./Footer";
10+
import { useDispatch } from "@/hooks/useTypedDispatch";
11+
import { setWeb3Address } from "@/store/feature/wallet.slice";
12+
import useWalletConnect from "@/hooks/useWalletConnect";
13+
import { modal } from "@/config/Web3Modal";
1014

1115
type Props = {
1216
connectionMethod: string;
@@ -18,6 +22,7 @@ type Props = {
1822
error: CustomError | undefined | null;
1923
clearError: () => void;
2024
show: boolean;
25+
openEditAddress: () => void;
2126
};
2227

2328
/**
@@ -49,7 +54,7 @@ interface FormValues {
4954
* @param {boolean} param0.show
5055
* @returns {*}
5156
*/
52-
export default function WalletAddressChangeForm({ connectionMethod, currentAddress, token, closeModal, onSave, loading, error, clearError, show }: Props) {
57+
export default function WalletAddressChangeForm({ connectionMethod, currentAddress, token, closeModal, onSave, loading, error, clearError, show, openEditAddress }: Props) {
5358
const { t } = useTranslation();
5459
const {
5560
watch,
@@ -58,11 +63,14 @@ export default function WalletAddressChangeForm({ connectionMethod, currentAddre
5863
setValue,
5964
formState: { errors },
6065
} = useForm<FormValues>();
66+
const dispatch = useDispatch();
6167

6268
const web3Adrress = useSelector((state) => state.web3Wallet.address);
6369

6470
const address = watch("address");
6571

72+
const { walletConnectAddress } = useWalletConnect();
73+
6674
const isMatchingTheExistingOne = useMemo(() => {
6775
if (!address || !currentAddress) return false;
6876
return currentAddress?.toLocaleLowerCase() === address?.toLocaleLowerCase();
@@ -88,6 +96,23 @@ export default function WalletAddressChangeForm({ connectionMethod, currentAddre
8896
if (!show) clear();
8997
}, [show]);
9098

99+
useEffect(() => {
100+
if (connectionMethod === "wallet") {
101+
setValue("address", walletConnectAddress || "");
102+
dispatch(setWeb3Address(walletConnectAddress));
103+
}
104+
}, [walletConnectAddress]);
105+
106+
useEffect(() => {
107+
modal.subscribeEvents(({ data }) => {
108+
if (data.event === "MODAL_CLOSE" && !address) {
109+
openEditAddress();
110+
} else if (data.event === "CONNECT_ERROR") {
111+
modal.close();
112+
}
113+
});
114+
}, []);
115+
91116
return (
92117
<form className="flex flex-col" onSubmit={handleSubmit(save)}>
93118
{show && (

src/components/sections/profile/modals/EditAddress/index.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useDispatch } from "@/hooks/useTypedDispatch";
44
import { useMultiSelector } from "@/hooks/useTypedSelector";
55
import { IRootState } from "@/store";
66
import { clearCurrentWallet } from "@/store/feature/user/wallets.slice";
7-
import { connectWallet, disconnectWallet } from "@/store/feature/wallet.slice";
87
import { fetchAllWallets, updateWallet } from "@/store/services/wallets.service";
98
import { CustomError } from "@/types/error";
109
import { Wallet } from "@/types/wallet";
@@ -13,7 +12,7 @@ import { ReactElement, useEffect, useMemo, useState } from "react";
1312
import WalletAddressChangeForm from "./_partials/Form";
1413
import { WalletInfo } from "./_partials/Info";
1514
import SelectWalletConnectionMethod from "./_partials/SelectConnectionMethod";
16-
15+
import useWalletConnect from "@/hooks/useWalletConnect";
1716

1817
/**
1918
* Interface for the edit profile props
@@ -46,7 +45,7 @@ export default function EditProfile({ show, wallet, onClose }: EditProfileProps)
4645
const [showWalletConnectionMethod, setShowWalletConnectionMethod] = useState(false);
4746
const [connectionMethod, setConnectionMethod] = useState("");
4847

49-
48+
const { openWeb3Modal, isConnected, disconnectWallet } = useWalletConnect();
5049
const dispatch = useDispatch();
5150

5251
const closeModal = () => {
@@ -91,12 +90,12 @@ export default function EditProfile({ show, wallet, onClose }: EditProfileProps)
9190
};
9291

9392
const disconnect = async () => {
94-
await dispatch(disconnectWallet());
93+
await disconnectWallet();
9594
};
9695

9796
const connect = async () => {
9897
try {
99-
await dispatch(connectWallet());
98+
isConnected ? disconnect() : openWeb3Modal();
10099
setShowEditAddress(true);
101100
} catch (e) {
102101
console.log(e);
@@ -137,7 +136,6 @@ export default function EditProfile({ show, wallet, onClose }: EditProfileProps)
137136
return wallets?.require_wallet_connection || false;
138137
}, [wallets?.require_wallet_connection]);
139138

140-
141139
const isWalletConnected = useMemo(() => {
142140
return requireWalletConnection && !!wallet?.address;
143141
}, [requireWalletConnection, wallet?.address]);
@@ -146,26 +144,32 @@ export default function EditProfile({ show, wallet, onClose }: EditProfileProps)
146144
return Boolean(showEditAddress && !showWalletConnectionMethod && connectionMethod);
147145
}, [connectionMethod, showEditAddress, showWalletConnectionMethod]);
148146

149-
150147
useEffect(() => {
151148
if (!currentAddress) {
152-
setShowWalletConnectionMethod(true);
149+
setShowWalletConnectionMethod(true);
153150
}
154151
}, [currentAddress]);
155152

156-
157153
return (
158154
<Modal show={show} onClose={closeModal}>
159155
<div className="px-6">
160156
<WalletHeader wallet={wallet} />
161157
{showWalletConnectionMethod && <SelectWalletConnectionMethod enableWalletConnection={requireWalletConnection} onSelect={setWalletConnectionMethod} />}
162158

163-
{!showWalletConnectionMethod && (
164-
<WalletInfo address={currentAddress} connectionMethod={connectionMethod} onClick={openEditAddress} />
165-
)}
166-
159+
{!showWalletConnectionMethod && <WalletInfo address={currentAddress} connectionMethod={connectionMethod} onClick={openEditAddress} />}
167160
</div>
168-
<WalletAddressChangeForm show={showForm} onSave={onSave} currentAddress={currentAddress} loading={loading} error={error} token={wallet?.token} connectionMethod={connectionMethod} closeModal={closeModal} clearError={() => setError(null)} />
161+
<WalletAddressChangeForm
162+
show={showForm}
163+
onSave={onSave}
164+
currentAddress={currentAddress}
165+
loading={loading}
166+
error={error}
167+
token={wallet?.token}
168+
connectionMethod={connectionMethod}
169+
closeModal={closeModal}
170+
clearError={() => setError(null)}
171+
openEditAddress={openEditAddress}
172+
/>
169173
</Modal>
170174
);
171175
}

0 commit comments

Comments
 (0)