Skip to content

Commit

Permalink
feat: added flow animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Dec 13, 2023
1 parent c40378d commit dc7d3bd
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 10 deletions.
53 changes: 50 additions & 3 deletions src/app/components/mint-unmint/components/mint-unmint.layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,47 @@
import { VStack } from '@chakra-ui/react';
import { HasChildren } from '@models/has-children';
import { VStack, keyframes } from '@chakra-ui/react';

interface MintUnmintLayoutProps {
children: React.ReactNode;
animate?: boolean;
step?: number;
}

export function MintUnmintLayout({ children, animate, step }: MintUnmintLayoutProps): React.JSX.Element {
const glow = keyframes`
0% { box-shadow: 0 0 5px rgba(255,255,255,0); }
25% { box-shadow: 0 0 10px rgba(255,255,255,0.5); }
50% { box-shadow: 0 0 15px rgba(255,255,255,0.75); }
75% { box-shadow: 0 0 10px rgba(255,255,255,0.5); }
100% { box-shadow: 0 0 5px rgba(7,232,216,0); }
`;

const swimUp = keyframes`
0% {
transform: translateY(0px);
opacity: 1;
}
5% {
transform: translateY(0px);
opacity: 0.5;
}
15% {
transform: translateY(0px);
opacity: 0;
}
25% {
transform: translateY(175px);
opacity: 0;
}
50% {
transform: translateY(75px);
opacity: 0.5;
}
100% {
transform: translateY(0);
opacity: 1;
}
`;

export function MintUnmintLayout({ children }: HasChildren): React.JSX.Element {
return (
<VStack
px={'15px'}
Expand All @@ -11,6 +51,13 @@ export function MintUnmintLayout({ children }: HasChildren): React.JSX.Element {
border={'1px solid'}
borderRadius={'md'}
borderColor={'border.cyan.01'}
css={{
animation: animate
? step === 0
? `${swimUp} 0.5s ease-out`
: `${glow} 0.5s 2 ease-in-out`
: 'none',
}}
>
{children}
</VStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { VStack } from '@chakra-ui/react';
import { HasChildren } from '@models/has-children';

export function MintLayout({ children }: HasChildren): React.JSX.Element {

return (
<VStack
alignContent={'start'}
Expand Down
13 changes: 11 additions & 2 deletions src/app/components/mint-unmint/mint-unmint.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';

import {
Expand Down Expand Up @@ -25,15 +26,23 @@ interface MintUnmintContainerProps {

export function MintUnmint({ address }: MintUnmintContainerProps): React.JSX.Element {
const dispatch = useDispatch();
const [animate, setAnimate] = useState(false);

const { activeTab } = useSelector((state: RootState) => state.mintunmint);
const { activeTab, mintStep, unmintStep } = useSelector((state: RootState) => state.mintunmint);

useEffect(() => {
setAnimate(true);
setTimeout(() => {
setAnimate(false);
}, 1000);
}, [mintStep, unmintStep]);

function handleTabsChange(index: number) {
dispatch(mintUnmintActions.setActiveTab(index));
}

return (
<MintUnmintLayout>
<MintUnmintLayout animate={animate} step={activeTab === 0 ? mintStep[0] : unmintStep[0]}>
<Tabs variant="unstyled" index={activeTab} onChange={handleTabsChange}>
<TabList>
<Tab>Mint</Tab>
Expand Down
30 changes: 25 additions & 5 deletions src/app/hooks/use-ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ export interface UseEthereumReturnType {
isLoaded: boolean;
}

function isMetaMask(provider: any): boolean {
console.log('provider', provider)

Check warning on line 41 in src/app/hooks/use-ethereum.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Unexpected console statement
console.log('typeof provider', typeof provider)

Check warning on line 42 in src/app/hooks/use-ethereum.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Unexpected console statement
console.log('provider !== null', provider !== null)

Check warning on line 43 in src/app/hooks/use-ethereum.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Unexpected console statement
console.log('metamaskInProvider', '_metamask' in provider )

Check warning on line 44 in src/app/hooks/use-ethereum.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

Unexpected console statement
console.log('isMetaMaskInProvider', 'isMetaMask' in provider)
console.log('provider.isMetaMask', provider.isMetaMask)
return (
typeof provider === 'object' &&
provider !== null &&
'_metamask' in provider &&
'isMetaMask' in provider &&
provider.isMetaMask === true
);
}

function throwEthereumError(message: string, error: any): void {
if (error.code === Logger.errors.CALL_EXCEPTION) {
throw new EthereumError(
Expand Down Expand Up @@ -94,15 +110,16 @@ export function useEthereum(): UseEthereumReturnType {
};
}

function getProvider(ethereum: any, walletType: WalletType): any {
if ('providers' in ethereum) {
return ethereum.providers.find((provider: any) => provider[`is${walletType}`]);
function getProvider(ethereum: any): any {
if (isMetaMask(ethereum)) {
return ethereum;
} else {
return undefined;
}
return ethereum[`is${walletType}`] ? ethereum : undefined;
}

function checkWalletProvider(ethereum: any, walletType: WalletType): any {
const ethereumWalletProvider = getProvider(ethereum, walletType);
const ethereumWalletProvider = getProvider(ethereum);
if (!ethereumWalletProvider) {
alert(`Install ${walletType}!`);
throw new EthereumError(`${walletType} wallet not found`);
Expand All @@ -113,6 +130,7 @@ export function useEthereum(): UseEthereumReturnType {
function getWalletProvider(walletType: WalletType): any {
const { ethereum } = window;

console.log('ethereum', ethereum)
if (!ethereum) {
alert('Install MetaMask!');
throw new EthereumError('No ethereum wallet found');
Expand Down Expand Up @@ -252,6 +270,8 @@ export function useEthereum(): UseEthereumReturnType {
if (!walletType) throw new Error('Wallet not initialized');
const walletProvider = getWalletProvider(walletType);

console.log('walletProvider', walletProvider);

const ethereumAccounts = await walletProvider.request({
method: 'eth_requestAccounts',
});
Expand Down
1 change: 1 addition & 0 deletions src/shared/models/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum WalletType {
Metamask = 'MetaMask',
Coinbase = 'CoinbaseWallet',
Trust = 'TrustWallet',
}

export interface Wallet {
Expand Down

0 comments on commit dc7d3bd

Please sign in to comment.