Skip to content

Commit

Permalink
Support Xverse (safeMode)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordankzf committed Aug 3, 2023
1 parent 75681f7 commit 67e9946
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions packages/sado-connect/src/components/SelectWalletModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export function SelectWalletModal({
network,
updateWallet,
updatePublicKey,
openModal,
updateFormat,
safeMode,
wallet,
format,
address,
Expand All @@ -49,13 +47,6 @@ export function SelectWalletModal({

// Unisat only returns one wallet by default
const unisatWallet = unisat[0];
const supportedFormats = ["segwit", "taproot"];
if (safeMode && !supportedFormats.includes(unisatWallet.format)) {
openModal();
throw Error(
"Only Native Segwit (P2WPKH) and Taproot (P2TR) addresses are supported. Switch to a supported address and connect again."
);
}
updateAddress(unisatWallet.address);
updatePublicKey(unisatWallet.pub);
updateWallet(Wallet.UNISAT);
Expand All @@ -76,12 +67,11 @@ export function SelectWalletModal({
const xverse = await ordit.xverse.getAddresses({
network,
});
const taprootAddress = xverse.find(
(address) => address.format === "nested-segwit"
);
updateAddress(taprootAddress.address);
updatePublicKey(taprootAddress.pub);
const xverseWallet = xverse[0];
updateAddress(xverseWallet.address);
updatePublicKey(xverseWallet.pub);
updateWallet(Wallet.XVERSE);
updateFormat(xverseWallet.format as AddressFormats);
closeModal();
} catch (err: any) {
if (err?.message === "Xverse not installed.") {
Expand All @@ -94,7 +84,7 @@ export function SelectWalletModal({

// Reconnect address change listener if there there is already a connected wallet
useEffect(() => {
if (address && publicKey && wallet && format) {
if (wallet === Wallet.UNISAT && address && publicKey && format) {
onConnectUnisatWallet();
}
}, []);
Expand Down Expand Up @@ -162,19 +152,17 @@ export function SelectWalletModal({
<img src={ChevronRightIcon} alt="Chevron Right" />
</button>
<hr className="horizontal-separator" />
{!safeMode && (
<button
type="button"
className="wallet-option-button"
onClick={async () => {
await onConnectXverseWallet();
}}
>
<img src={XverseWalletIcon} alt="Xverse Wallet" />
<span className="wallet-option-label">Xverse</span>
<img src={ChevronRightIcon} alt="Chevron Right" />
</button>
)}
<button
type="button"
className="wallet-option-button"
onClick={async () => {
await onConnectXverseWallet();
}}
>
<img src={XverseWalletIcon} alt="Xverse Wallet" />
<span className="wallet-option-label">Xverse</span>
<img src={ChevronRightIcon} alt="Chevron Right" />
</button>
</section>
) : (
<>
Expand Down

0 comments on commit 67e9946

Please sign in to comment.