Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions react/lib/util/cashtab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,31 @@ export const sendXecWithCashtab = async (address: string, amount: string | numbe
* @param fallbackUrl - Optional fallback URL if extension is not available
*/
export const openCashtabPayment = async (bip21Url: string, fallbackUrl?: string): Promise<void> => {
const webUrl = fallbackUrl || `https://cashtab.com/#/send?bip21=${bip21Url}`;

try {
const isAvailable = await getCashtabProviderStatus();

if (isAvailable) {
cashtab.sendBip21(bip21Url);
await cashtab.sendBip21(bip21Url);
} else {
const webUrl = fallbackUrl || `https://cashtab.com/#/send?bip21=${bip21Url}`;
window.open(webUrl, '_blank');
return;
}
} catch (error) {
if (error instanceof CashtabAddressDeniedError) {
// User rejected the transaction - do nothing for now
// This case is handled here in case we want to add specific behavior in the future
// User rejected the transaction - do nothing
return;
}

const webUrl = fallbackUrl || `https://cashtab.com/#/send?bip21=${bip21Url}`;
if (
error instanceof CashtabExtensionUnavailableError ||
error instanceof CashtabTimeoutError
) {
// Extension not available or timed out: fallback to web
window.open(webUrl, '_blank');
return;
}
// Unknown error: still attempt web fallback
window.open(webUrl, '_blank');
}
};
Expand Down