Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: no refund file download in mobile EVM browser #760

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
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
25 changes: 25 additions & 0 deletions e2e/evm/noBrowserWallet.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { test } from "@playwright/test";

import dict from "../../src/i18n/i18n";

test.describe("EVM no browser wallet", () => {
test("should show when no browser wallet is detected", async ({ page }) => {
await page.goto("/");

await page
.locator(
"div:nth-child(3) > .asset-wrap > .asset > .asset-selection",
)
.click();
await page.getByTestId("select-RBTC").click();

await page
.getByRole("button", { name: dict.en.connect_wallet })
.click();

// Click it to make sure it exists
await page
.getByRole("heading", { name: dict.en.no_browser_wallet })
.click();
});
});
11 changes: 2 additions & 9 deletions src/components/ConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import type { EIP6963ProviderInfo } from "../consts/Types";
import { useCreateContext } from "../context/Create";
import { useGlobalContext } from "../context/Global";
import { customDerivationPathRdns, useWeb3Signer } from "../context/Web3";
import { useWeb3Signer } from "../context/Web3";
import "../style/web3.scss";
import { formatError } from "../utils/errors";
import { cropString, isMobile } from "../utils/helper";
Expand All @@ -25,20 +25,13 @@ const Modal = (props: {
setShow: Setter<boolean>;
}) => {
const { t, notify } = useGlobalContext();
const { providers, connectProvider } = useWeb3Signer();
const { providers, connectProvider, hasBrowserWallet } = useWeb3Signer();

const [showDerivationPaths, setShowDerivationPaths] =
createSignal<boolean>(false);
const [hardwareProvider, setHardwareProvider] =
createSignal<EIP6963ProviderInfo>(undefined);

const hasBrowserWallet = createMemo(() => {
return Object.values(providers()).some(
(provider) =>
!customDerivationPathRdns.includes(provider.info.rdns),
);
});

const Provider = (providerProps: { provider: EIP6963ProviderInfo }) => {
return (
<div
Expand Down
11 changes: 8 additions & 3 deletions src/components/CreateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { fetchBolt12Invoice, getPairs } from "../utils/boltzClient";
import { formatAmount } from "../utils/denomination";
import { formatError } from "../utils/errors";
import { HardwareSigner } from "../utils/hardware/HadwareSigner";
import { coalesceLn } from "../utils/helper";
import { coalesceLn, isMobile } from "../utils/helper";
import { fetchBip353, fetchLnurl } from "../utils/invoice";
import {
SomeSwap,
Expand Down Expand Up @@ -63,7 +63,8 @@ export const CreateButton = () => {
bolt12Offer,
setBolt12Offer,
} = useCreateContext();
const { getEtherSwap, signer, providers } = useWeb3Signer();
const { getEtherSwap, signer, providers, hasBrowserWallet } =
useWeb3Signer();

const [buttonDisable, setButtonDisable] = createSignal(false);
const [buttonClass, setButtonClass] = createSignal("btn");
Expand Down Expand Up @@ -353,11 +354,15 @@ export const CreateButton = () => {
setOnchainAddress("");
setAddressValid(false);

// Mobile EVM browsers struggle with downloading files
const isMobileEvmBrowser = () => isMobile() && hasBrowserWallet();

// No backups needed for Reverse Swaps or when we send RBTC
if (
isRecklessMode() ||
swapType() === SwapType.Reverse ||
assetSend() === RBTC
assetSend() === RBTC ||
isMobileEvmBrowser()
) {
navigate("/swap/" + data.id);
} else {
Expand Down
9 changes: 9 additions & 0 deletions src/context/Web3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ const customDerivationPathRdns: string[] = [

const Web3SignerContext = createContext<{
providers: Accessor<Record<string, EIP6963ProviderDetail>>;
hasBrowserWallet: Accessor<boolean>;

connectProvider: (rdns: string) => Promise<void>;
connectProviderForAddress: (
address: string,
derivationPath?: string,
) => Promise<void>;

signer: Accessor<Signer | undefined>;
clearSigner: () => void;

Expand Down Expand Up @@ -116,9 +119,12 @@ const Web3SignerProvider = (props: {
const [rawProvider, setRawProvider] = createSignal<
EIP1193Provider | undefined
>(undefined);
const [hasBrowserWallet, setHasBrowserWallet] =
createSignal<boolean>(false);

onMount(() => {
if (window.ethereum !== undefined) {
setHasBrowserWallet(true);
setProviders({
...providers(),
[browserRdns]: {
Expand All @@ -139,6 +145,8 @@ const Web3SignerProvider = (props: {
log.debug(
`Found EIP-6963 wallet: ${event.detail.info.rdns}: ${event.detail.info.name}`,
);
setHasBrowserWallet(true);

const existingProviders = { ...providers() };

// We should not show the browser provider when an EIP-6963 provider is found
Expand Down Expand Up @@ -269,6 +277,7 @@ const Web3SignerProvider = (props: {
getEtherSwap,
switchNetwork,
connectProvider,
hasBrowserWallet,
connectProviderForAddress,
getContracts: contracts,
clearSigner: () => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ChainSwap, ReverseSwap, SomeSwap, SubmarineSwap } from "./swapCreator";

export const isIos = () =>
!!navigator.userAgent.match(/iphone|ipad/gi) || false;

export const isMobile = () =>
isIos() || !!navigator.userAgent.match(/android|blackberry/gi) || false;

Expand Down