generated from veeso-dev/rust-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.
fix: allow user to choose which wallet to use
- Loading branch information
Showing
14 changed files
with
299 additions
and
42 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
Binary file added
BIN
+1.71 KB
src/ekoke_erc20_swap_frontend/src/assets/images/bitfinity-wallet.webp
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions
31
src/ekoke_erc20_swap_frontend/src/js/components/App/AppContext.tsx
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,31 @@ | ||
import * as React from 'react'; | ||
import { WalletProvider } from 'react-ic-wallet'; | ||
import { getUserIcWallet } from '../../storage'; | ||
|
||
interface Context { | ||
icWallet?: WalletProvider; | ||
setIcWallet?: (icWallet: WalletProvider | undefined) => void; | ||
} | ||
|
||
const AppContext = React.createContext<Context>({}); | ||
|
||
const AppContextProvider = ({ children }: { children?: React.ReactNode }) => { | ||
const [icWallet, setIcWallet] = React.useState<WalletProvider | undefined>(); | ||
|
||
React.useEffect(() => { | ||
const userWallet = getUserIcWallet(); | ||
if (userWallet) { | ||
setIcWallet(userWallet); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<AppContext.Provider value={{ icWallet, setIcWallet }}> | ||
{children} | ||
</AppContext.Provider> | ||
); | ||
}; | ||
|
||
export default AppContextProvider; | ||
|
||
export const useAppContext = () => React.useContext(AppContext); |
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
78 changes: 60 additions & 18 deletions
78
src/ekoke_erc20_swap_frontend/src/js/components/IcConnect.tsx
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
31 changes: 31 additions & 0 deletions
31
src/ekoke_erc20_swap_frontend/src/js/components/IcConnect/DisconnectPopup.tsx
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,31 @@ | ||
import * as React from 'react'; | ||
|
||
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; |
77 changes: 77 additions & 0 deletions
77
src/ekoke_erc20_swap_frontend/src/js/components/IcConnect/WalletSelector.tsx
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,77 @@ | ||
import * as React from 'react'; | ||
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
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,28 @@ | ||
import { WalletProvider } from 'react-ic-wallet'; | ||
|
||
interface UserPreferences { | ||
icWallet?: WalletProvider; | ||
} | ||
|
||
const getPreferences = (): UserPreferences | null => { | ||
try { | ||
const storedPreferences = localStorage.getItem('userPreferences'); | ||
return storedPreferences | ||
? (JSON.parse(storedPreferences) as UserPreferences) | ||
: null; | ||
} catch (error) { | ||
console.error('Failed to fetch from local storage:', error); | ||
return null; | ||
} | ||
}; | ||
|
||
export const getUserIcWallet = (): WalletProvider | undefined => { | ||
const preferences = getPreferences(); | ||
return preferences?.icWallet; | ||
}; | ||
|
||
export const setUserIcWallet = (icWallet: WalletProvider | undefined): void => { | ||
const preferences = getPreferences() || {}; | ||
preferences.icWallet = icWallet; | ||
localStorage.setItem('userPreferences', JSON.stringify(preferences)); | ||
}; |
Oops, something went wrong.