|
1 | 1 | import React, { useState } from 'react'; |
2 | | -import { useWallet } from 'useink'; |
| 2 | +import { useWallet, useInstalledWallets } from 'useink'; |
3 | 3 | import { FaAngleDown, FaAngleUp } from 'react-icons/fa'; |
4 | 4 | import { Archivo } from 'next/font/google'; |
5 | 5 | const archivo = Archivo({ subsets: ['latin'] }); |
| 6 | +import Text from '../../components/generals/text'; |
6 | 7 |
|
7 | 8 | const Index = () => { |
| 9 | + const { account, accounts, isConnected, setAccount, connect, disconnect } = useWallet(); |
| 10 | + const wallets = useInstalledWallets(); |
| 11 | + const [showWallets, setShowWallets] = useState(false); |
| 12 | + const [show, setShow] = useState<boolean>(false); |
| 13 | + |
| 14 | + const handleAccount = (account: any) => { |
| 15 | + setAccount(account); |
| 16 | + setShow(!show); |
| 17 | + }; |
| 18 | + |
| 19 | + if (isConnected) |
| 20 | + return ( |
| 21 | + <div className="flex absolute w-full md:w-fit"> |
| 22 | + <div |
| 23 | + className={ |
| 24 | + show |
| 25 | + ? 'pl-4 pr-2 py-3 border-oppurple border-2 rounded-[5px] flex ml-auto mt-6 w-full md:w-fit h-fit bg-[#FFFFFF] justify-between md:justify-normal z-50' |
| 26 | + : 'pl-4 items-center pr-2 py-3 border-oppurple border-2 rounded-[5px] flex ml-auto mt-6 w-full md:w-fit h-fit bg-[#FFFFFF] justify-between md:justify-normal z-50' |
| 27 | + } |
| 28 | + > |
| 29 | + <div className="flex flex-col w-full"> |
| 30 | + <p |
| 31 | + className={ |
| 32 | + show |
| 33 | + ? `text-[14px] uppercase p-4 w-full cursor-pointer text-oppurple font-normal tracking-[1.25px] rounded ${archivo.className} hover:bg-oppurple hover:text-opwhite transition duration-200` |
| 34 | + : `text-[14px] uppercase w-full cursor-pointer text-oppurple font-normal tracking-[1.25px] rounded ${archivo.className} hover:bg-oppurple hover:text-opwhite transition duration-200` |
| 35 | + } |
| 36 | + > |
| 37 | + {account?.name} ({account?.address.slice(0, 5)}... |
| 38 | + {account?.address.slice(account?.address.length - 5, account?.address.length)}) |
| 39 | + </p> |
| 40 | + {show && ( |
| 41 | + <div className="flex flex-col gap-[10px] mt-[10px]"> |
| 42 | + <div className="border-oppurple border w-full"></div> |
| 43 | + {accounts?.map((a) => ( |
| 44 | + <div |
| 45 | + key={a} |
| 46 | + className={`text-[14px] uppercase w-full p-4 cursor-pointer text-oppurple font-normal tracking-[1.25px] rounded ${archivo.className} hover:bg-oppurple hover:text-opwhite transition duration-200`} |
| 47 | + onClick={() => handleAccount(a)} |
| 48 | + > |
| 49 | + {a?.name} ({account?.address.slice(0, 5)}... |
| 50 | + {a?.address.slice(a?.address.length - 5, a?.address.length)}) |
| 51 | + </div> |
| 52 | + ))} |
| 53 | + <button |
| 54 | + className={`items-center text-center bg-oppurple p-1.5 flex gap-[10px] rounded-[5px] py-[10px] px-[10px] text-[14px] uppercase w-full justify-center text-opwhite font-normal tracking-[1.25px] ${archivo.className}`} |
| 55 | + onClick={disconnect} |
| 56 | + > |
| 57 | + disconnect |
| 58 | + </button> |
| 59 | + </div> |
| 60 | + )} |
| 61 | + </div> |
| 62 | + <div className="cursor-pointer px-4 mt-1.5" onClick={() => setShow(!show)}> |
| 63 | + {show ? <FaAngleUp /> : <FaAngleDown />} |
| 64 | + </div> |
| 65 | + </div> |
| 66 | + </div> |
| 67 | + ); |
| 68 | + |
| 69 | + return ( |
| 70 | + <div> |
| 71 | + <div |
| 72 | + className={ |
| 73 | + showWallets |
| 74 | + ? 'pl-4 pr-2 py-3 border-oppurple border-2 rounded-[5px] flex ml-auto mt-6 w-full md:w-fit h-fit bg-[#FFFFFF] justify-between md:justify-normal z-50' |
| 75 | + : 'cursor-pointer pl-4 pr-2 py-3 border-oppurple border-2 rounded-[5px] flex ml-auto mt-6 w-full md:w-fit h-fit bg-oppurple text-opwhite justify-between md:justify-normal z-50' |
| 76 | + } |
| 77 | + > |
| 78 | + <div className="flex w-full"> |
| 79 | + {showWallets ? ( |
| 80 | + <div className="flex w-full"> |
| 81 | + <ul className="flex flex-col"> |
| 82 | + {wallets.map((w: any) => ( |
| 83 | + <li key={w.title}> |
| 84 | + <p |
| 85 | + onClick={() => connect(w.extensionName)} |
| 86 | + className={`text-[14px] uppercase w-full p-4 cursor-pointer text-oppurple font-normal tracking-[1.25px] rounded ${archivo.className} hover:bg-oppurple hover:text-opwhite transition duration-200`} |
| 87 | + > |
| 88 | + Connect to {w.title} |
| 89 | + </p> |
| 90 | + </li> |
| 91 | + ))} |
| 92 | + </ul> |
| 93 | + <div className="p-2 cursor-pointer"> |
| 94 | + <FaAngleUp onClick={() => setShowWallets(false)} /> |
| 95 | + </div> |
| 96 | + </div> |
| 97 | + ) : ( |
| 98 | + <div className="flex gap-3 items-center"> |
| 99 | + <p |
| 100 | + className={`items-center text-center bg-oppurple text-[14px] uppercase w-full justify-center text-opwhite font-normal tracking-[1.25px] ${archivo.className}`} |
| 101 | + > |
| 102 | + connect |
| 103 | + </p> |
| 104 | + <div className="p-2 cursor-pointer"> |
| 105 | + <FaAngleDown onClick={() => setShowWallets(true)} /> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + )} |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + ); |
| 113 | + |
| 114 | + /* |
8 | 115 | const { account, accounts, setAccount, connect, disconnect } = useWallet(); |
9 | 116 | const [show, setShow] = useState<boolean>(false); |
| 117 | +
|
10 | 118 | const handleAccount = (account: any) => { |
11 | 119 | setAccount(account); |
12 | 120 | setShow(!show); |
13 | 121 | }; |
14 | 122 |
|
| 123 | + const wallets = useInstalledWallets(); |
| 124 | +
|
15 | 125 | return ( |
16 | 126 | <div className="flex absolute w-full md:w-fit"> |
17 | 127 | <div className="pl-4 pr-2 py-3 border-oppurple border-2 rounded-[5px] flex ml-auto mt-6 w-full md:w-fit h-fit bg-[#FFFFFF] justify-between md:justify-normal z-50"> |
@@ -43,6 +153,7 @@ const Index = () => { |
43 | 153 | </div> |
44 | 154 | </div> |
45 | 155 | ); |
| 156 | + */ |
46 | 157 | }; |
47 | 158 |
|
48 | 159 | export default Index; |
0 commit comments