generated from veeso-dev/fe-react-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
492 additions
and
56 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 |
---|---|---|
@@ -1,16 +1,29 @@ | ||
import 'react-loading-skeleton/dist/skeleton.css'; | ||
import { IcWalletProvider } from 'react-ic-wallet'; | ||
|
||
import AppLayout from './js/components/AppLayout'; | ||
import AppContextProvider from './js/components/App/AppContext'; | ||
import AppContextProvider, { | ||
useAppContext, | ||
} from './js/components/App/AppContext'; | ||
import AppError from './js/components/Status/AppError'; | ||
import AppSuccess from './js/components/Status/AppSuccess'; | ||
|
||
const App = () => ( | ||
<AppContextProvider> | ||
<AppError /> | ||
<AppSuccess /> | ||
<AppLayout /> | ||
<AppLayoutWrapper /> | ||
</AppContextProvider> | ||
); | ||
|
||
const AppLayoutWrapper = () => { | ||
const { icWallet } = useAppContext(); | ||
|
||
return ( | ||
<IcWalletProvider provider={icWallet}> | ||
<AppError /> | ||
<AppSuccess /> | ||
<AppLayout /> | ||
</IcWalletProvider> | ||
); | ||
}; | ||
|
||
export default App; |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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,93 @@ | ||
import * as React from 'react'; | ||
import { WalletProvider, useIcWallet } from 'react-ic-wallet'; | ||
|
||
import Button from './reusable/Button'; | ||
import Container from './reusable/Container'; | ||
import InternetComputer from './svg/InternetComputer'; | ||
import { useAppContext } from './App/AppContext'; | ||
import WalletSelector from './IcConnect/WalletSelector'; | ||
import { setUserIcWallet } from '../utils/storage'; | ||
import DisconnectPopup from './IcConnect/DisconnectPopup'; | ||
|
||
const IcConnect = () => { | ||
const { status, connect, disconnect, principal } = useIcWallet(); | ||
const { icWallet, setIcWallet } = useAppContext(); | ||
const [showWalletSelector, setShowWalletSelector] = React.useState(false); | ||
const [showDisconnectPopup, setShowDisconnectPopup] = React.useState(false); | ||
|
||
const disabled = ['initializing', 'unavailable', 'connecting'].includes( | ||
status, | ||
); | ||
|
||
const onDisconnect = () => { | ||
if (setIcWallet) { | ||
setIcWallet(undefined); | ||
} | ||
setUserIcWallet(undefined); | ||
|
||
return disconnect(); | ||
}; | ||
|
||
const onClick = () => { | ||
if (status === 'notConnected') { | ||
setShowWalletSelector(true); | ||
} else if (status === 'connected') { | ||
setShowDisconnectPopup(true); | ||
} | ||
return undefined; | ||
}; | ||
|
||
const onWalletSelect = (wallet: WalletProvider) => { | ||
if (setIcWallet) { | ||
setIcWallet(wallet); | ||
} | ||
setShowWalletSelector(false); | ||
}; | ||
|
||
const text = () => { | ||
if (status === 'initializing') return 'Initializing...'; | ||
if (status === 'unavailable') return 'IC Wallet not available'; | ||
if (status === 'notConnected') return 'Login'; | ||
if (status === 'connecting') return 'Connecting...'; | ||
if (status === 'connected') | ||
return `${principal.toString().substring(0, 18)}...`; | ||
return undefined; | ||
}; | ||
|
||
React.useEffect(() => { | ||
console.log('ic status', status, 'ic wallet', icWallet); | ||
if (icWallet !== undefined && status === 'notConnected') { | ||
connect() | ||
.then(() => { | ||
setUserIcWallet(icWallet); | ||
}) | ||
.catch((e) => { | ||
console.error('Failed to connect to wallet', e); | ||
}); | ||
} | ||
}, [icWallet, status, connect]); | ||
|
||
return ( | ||
<> | ||
<Container.FlexRow className="items-center gap-8"> | ||
<Button.Alternative | ||
className="my-0 !mb-0" | ||
onClick={onClick} | ||
disabled={disabled} | ||
> | ||
<InternetComputer className="inline w-[32px] mr-2" /> | ||
{text()} | ||
</Button.Alternative> | ||
</Container.FlexRow> | ||
{showWalletSelector ? <WalletSelector onSelect={onWalletSelect} /> : null} | ||
{showDisconnectPopup ? ( | ||
<DisconnectPopup | ||
onDisconnect={onDisconnect} | ||
onDismiss={() => setShowDisconnectPopup(false)} | ||
/> | ||
) : null} | ||
</> | ||
); | ||
}; | ||
|
||
export default IcConnect; |
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,29 @@ | ||
import Container from '../reusable/Container'; | ||
import Button from '../reusable/Button'; | ||
|
||
const DisconnectPopup = ({ | ||
onDisconnect, | ||
onDismiss, | ||
}: { | ||
onDisconnect: () => void; | ||
onDismiss: () => void; | ||
}) => { | ||
return ( | ||
<Container.Container className="h-screen left-0 overflow-hidden fixed right-0 top-0 w-screen z-50"> | ||
<Container.Container className="bg-gray-800/60 h-screen w-screen" /> | ||
<Container.Container className="bg-white bottom-0 h-fit sm:h-[70vh] sm:rounded-t-xl left-0 m-auto p-8 fixed right-0 top-0 sm:top-auto sm:bottom-0 w-fit min-w-[25%] sm:w-full"> | ||
<Container.FlexCols className="gap-4 text-lg p-4"> | ||
<span className="text-lg text-center block text-text"> | ||
Do you want to disconnect your wallet? | ||
</span> | ||
<Container.FlexResponsiveRow className="items-center justify-between gap-8"> | ||
<Button.Danger onClick={onDisconnect}>Disconnect</Button.Danger> | ||
<Button.Alternative onClick={onDismiss}>Cancel</Button.Alternative> | ||
</Container.FlexResponsiveRow> | ||
</Container.FlexCols> | ||
</Container.Container> | ||
</Container.Container> | ||
); | ||
}; | ||
|
||
export default DisconnectPopup; |
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,76 @@ | ||
import { WalletProvider } from 'react-ic-wallet'; | ||
|
||
import Container from '../reusable/Container'; | ||
import Button from '../reusable/Button'; | ||
|
||
import IcpWalletLogo from '../../../assets/images/icp-wallet.webp'; | ||
import BitfinityWalletLogo from '../../../assets/images/bitfinity-wallet.webp'; | ||
import PlugWalletLogo from '../../../assets/images/plug-wallet.webp'; | ||
|
||
const WalletSelector = ({ | ||
onSelect, | ||
}: { | ||
onSelect: (wallet: WalletProvider) => void; | ||
}) => { | ||
return ( | ||
<Container.Container className="h-screen left-0 overflow-hidden fixed right-0 top-0 w-screen z-50"> | ||
<Container.Container className="bg-gray-800/60 h-screen w-screen" /> | ||
<Container.Container className="bg-white bottom-0 h-fit sm:h-[70vh] sm:rounded-t-xl left-0 m-auto p-8 fixed right-0 top-0 sm:top-auto sm:bottom-0 w-fit min-w-[25%] sm:w-full"> | ||
<Container.FlexCols className="gap-4 text-lg p-4"> | ||
<span className="text-lg text-center block text-text"> | ||
Connect a wallet | ||
</span> | ||
<Container.Container className="grid grid-cols-2 sm:grid-cols-1 gap-4 px-4"> | ||
<Wallet | ||
logo={IcpWalletLogo} | ||
name="Internet Identity" | ||
onSelect={onSelect} | ||
wallet={WalletProvider.Dfinity} | ||
/> | ||
<Wallet | ||
logo={BitfinityWalletLogo} | ||
name="Bitfinity Wallet" | ||
onSelect={onSelect} | ||
wallet={WalletProvider.Bitfinity} | ||
/> | ||
<Wallet | ||
logo={PlugWalletLogo} | ||
name="Plug" | ||
onSelect={onSelect} | ||
wallet={WalletProvider.Plug} | ||
/> | ||
</Container.Container> | ||
</Container.FlexCols> | ||
</Container.Container> | ||
</Container.Container> | ||
); | ||
}; | ||
|
||
const Wallet = ({ | ||
logo, | ||
name, | ||
onSelect, | ||
wallet, | ||
}: { | ||
logo: string; | ||
name: string; | ||
onSelect: (wallet: WalletProvider) => void; | ||
wallet: WalletProvider; | ||
}) => ( | ||
<Container.Container> | ||
<Button.Alternative className="w-full" onClick={() => onSelect(wallet)}> | ||
<Container.FlexRow className="items-center justify-between w-full"> | ||
<span className="text-lg text-text">{name}</span> | ||
<img | ||
className="rounded-full bg-white border border-gray-300 p-1 w-[48px] h-[48px]" | ||
src={logo} | ||
alt={name} | ||
width={64} | ||
height={64} | ||
/> | ||
</Container.FlexRow> | ||
</Button.Alternative> | ||
</Container.Container> | ||
); | ||
|
||
export default WalletSelector; |
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
Oops, something went wrong.