generated from damla/nextjs-dApp-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from damla/delete-web3-ui-kit
- Loading branch information
Showing
18 changed files
with
700 additions
and
795 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { useRouter } from 'next/router'; | ||
import { useEffect } from 'react'; | ||
import { useMoralis } from 'react-moralis'; | ||
import { classNames, getConnectWalletTexts } from '../../../utils/utils'; | ||
import Icon, { Icons } from '../Icon/Icon'; | ||
|
||
interface Props { | ||
icon?: boolean; | ||
defaultText?: string; | ||
} | ||
|
||
const ConnectWallet = ({ icon, defaultText }: Props) => { | ||
const { authenticate, isAuthenticated, isAuthenticating } = useMoralis(); | ||
|
||
const router = useRouter(); | ||
const currentLocale = router.locale || 'en'; | ||
|
||
const { text, connecting } = getConnectWalletTexts(currentLocale); | ||
|
||
useEffect(() => { | ||
if (isAuthenticated) router.replace('/dashboard'); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isAuthenticated]); | ||
|
||
const login = async () => { | ||
if (!isAuthenticated && !isAuthenticating) { | ||
await authenticate({ signingMessage: 'Log in using Moralis' }) | ||
.then(function (user) { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
console.log(user!.get('ethAddress')); | ||
console.log('logged in user:', user); | ||
}) | ||
.catch(function (err) { | ||
console.log(err); | ||
// TODO: error notification for non-wallet users | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<button | ||
onClick={login} | ||
disabled={isAuthenticated} | ||
type="button" | ||
className={`border focus:ring-4 focus:outline-none font-medium btn rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center focus:ring-[#2B85B0] bg-[#2B85B0] border-[#2B85B0] hover:border-gray-800 text-white hover:bg-gray-700 ${ | ||
isAuthenticating && classNames('opacity-50', 'cursor-not-allowed') | ||
}`} | ||
> | ||
<> | ||
{icon && <Icon icon={Icons.METAMASK} alt="metamask" />} | ||
<span className={`${icon && 'hidden md:block'}`}> | ||
{isAuthenticating ? connecting : defaultText ? defaultText : text} | ||
</span> | ||
</> | ||
</button> | ||
); | ||
}; | ||
|
||
export default ConnectWallet; |
Oops, something went wrong.
06f01e3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-dapp-example – ./
next-dapp-example-damla.vercel.app
next-dapp-example-git-main-damla.vercel.app
nextjs-dapp-example.vercel.app