-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extension loading spinner and current wallet icon
- Loading branch information
Showing
5 changed files
with
129 additions
and
31 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
55 changes: 55 additions & 0 deletions
55
packages/sado-connect/src/components/SelectWalletModal/WalletButton.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,55 @@ | ||
import { useState } from "react"; | ||
import ChevronRightIcon from "../../assets/chevron-right.svg"; | ||
import LoadingIcon from "../../assets/loading.svg"; | ||
|
||
interface WalletButtonProp { | ||
name: string; | ||
onConnect: () => Promise<boolean>; | ||
icon: string; | ||
imageClassOverride?: string; | ||
setErrorMessage: (msg: string) => void; | ||
} | ||
|
||
export function WalletButton({ | ||
name, | ||
onConnect, | ||
icon, | ||
imageClassOverride, | ||
setErrorMessage, | ||
}: WalletButtonProp) { | ||
const [loading, setLoading] = useState(false); | ||
return ( | ||
<button | ||
type="button" | ||
className="wallet-option-button" | ||
onClick={async () => { | ||
setLoading(true); | ||
const timeout = (resolve) => setTimeout(() => resolve("timeout"), 5000); | ||
const success = await Promise.race([onConnect(), new Promise(timeout)]); | ||
if (success === "timeout") { | ||
setErrorMessage( | ||
"No wallet pop-up? The extension is not responding. Try reloading your browser.", | ||
); | ||
} else { | ||
setLoading(false); | ||
} | ||
}} | ||
> | ||
<img | ||
src={icon} | ||
className={imageClassOverride} | ||
alt={`Connect ${name} Wallet`} | ||
/> | ||
<span className="wallet-option-label">{name}</span> | ||
{loading ? ( | ||
<img | ||
src={LoadingIcon} | ||
width={40} | ||
alt={`${name} wallet extension is loading`} | ||
/> | ||
) : ( | ||
<img src={ChevronRightIcon} alt="Chevron Right" /> | ||
)} | ||
</button> | ||
); | ||
} |
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