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 dapps webview loading #548

Merged
merged 2 commits into from
Oct 24, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ This document logs notable, developer-facing updates to the NEAR Mobile Wallet.

### 🐛 Bug Fixes

- Fix dapps webview loading [fix/dapps-webview-loading](https://github.com/Peersyst/near-mobile-wallet/pull/548)
- Fix account being duplicated when creating new account [fix/create-account-duplicated](https://github.com/Peersyst/near-mobile-wallet/pull/546)
- Fix withdraw showing success when failing [fix/android-opening-default-browser](https://github.com/Peersyst/near-mobile-wallet/pull/545)
- Fix Android opening default browser [fix/android-opening-default-browser](https://github.com/Peersyst/near-mobile-wallet/pull/544)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CircularProgress } from "@peersyst/react-native-components";
import styled from "@peersyst/react-native-styled";
import { NearLoadingIcon } from "icons";
import { LoadingLogoIconProps, LoadingLogoRootProps } from "./LoadingLogo.types";
import { alpha } from "@peersyst/react-utils";

export const LoadingLogoIconRoot = styled(CircularProgress)<LoadingLogoRootProps>(({ size, color }) => ({
size,
thickness: 3,
color,
backgroundColor: alpha(color, 0.2),
}));

export const LoadingLogoIcon = styled(NearLoadingIcon)<LoadingLogoIconProps>(({ size, color }) => ({
color,
fontSize: size * 0.4,
}));
17 changes: 17 additions & 0 deletions src/module/common/component/feedback/LoadingLogo/LoadingLogo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useColor } from "@peersyst/react-native-components";
import { LoadingLogoIcon, LoadingLogoIconRoot } from "./LoadingLogo.styles";
import { LoadingLogoProps } from "./LoadingLogo.types";
import useWalletColor from "module/wallet/hook/useWalletColor";

export function LoadingLogo({ style = {}, color: colorProp }: LoadingLogoProps): JSX.Element {
const walletColor = useWalletColor();
const parsedThemeColor = useColor(colorProp);
const { size = 120, color: styleColor, ...restStyle } = style;
const color = styleColor ?? parsedThemeColor ?? walletColor;

return (
<LoadingLogoIconRoot size={size} color={color} style={restStyle}>
<LoadingLogoIcon size={size} color={color} />
</LoadingLogoIconRoot>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { CircularProgressStyle, ThemeColor } from "@peersyst/react-native-components";

export type LoadingLogoProps = {
color?: ThemeColor;
style?: CircularProgressStyle;
};

export type LoadingLogoRootProps = {
color: string;
size: number;
};

export type LoadingLogoIconProps = LoadingLogoRootProps;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import styled from "@peersyst/react-native-styled";
import { CircularProgress, Col } from "@peersyst/react-native-components";
import { Col } from "@peersyst/react-native-components";
import GradientPage from "module/common/component/layout/GradientPage/GradientPage";
import { View } from "react-native";
import { CircleCheckIcon, NearLoadingIcon } from "icons";
import { CircleCheckIcon } from "icons";
import Typography from "module/common/component/display/Typography/Typography";

export const DarkLoadingModalOverlay = styled(View)(({ theme }) => ({
Expand Down Expand Up @@ -32,15 +32,3 @@ export const SuccessIcon = styled(CircleCheckIcon)(({ theme }) => ({
export const LoadingModalMessage = styled(Typography)(({ theme }) => ({
color: theme.palette.white,
}));

export const LoadingModalContentIcon = styled(CircularProgress)(({ theme }) => ({
size: 120,
thickness: 3,
color: theme.palette.white,
backgroundColor: theme.palette.overlay["20%"],
}));

export const LoadingModalIcon = styled(NearLoadingIcon)(({ theme }) => ({
color: theme.palette.white,
fontSize: 48,
}));
15 changes: 3 additions & 12 deletions src/module/common/component/feedback/LoadingModal/LoadingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { LoadingModalProps } from "./LoadingModal.types";
import {
DarkLoadingModalOverlay,
LoadingModalRoot,
SuccessIcon,
LoadingModalContent,
LoadingModalMessage,
LoadingModalContentIcon,
LoadingModalIcon,
} from "./LoadingModal.styles";
import { DarkLoadingModalOverlay, LoadingModalRoot, SuccessIcon, LoadingModalContent, LoadingModalMessage } from "./LoadingModal.styles";
import { useEffect, useState } from "react";
import { notificationAsync, NotificationFeedbackType } from "expo-haptics";
import useTranslate from "module/common/hook/useTranslate";
import { Backdrop, Col } from "@peersyst/react-native-components";
import Button from "module/common/component/input/Button/Button";
import { LoadingLogo } from "../LoadingLogo/LoadingLogo";

const LoadingModal = ({
loading,
Expand Down Expand Up @@ -75,9 +68,7 @@ const LoadingModal = ({
</>
) : (
<Col alignItems="center" gap={30} flex={1} justifyContent="center">
<LoadingModalContentIcon>
<LoadingModalIcon />
</LoadingModalContentIcon>
<LoadingLogo color="white" />
<Col gap={12} alignItems="center">
<LoadingModalMessage variant="body1Strong" color="text">
{processingMessage || translate("processing")}
Expand Down
16 changes: 16 additions & 0 deletions src/module/dapp/screen/BrowserScreen/BrowserScreen.styles.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
import { Col } from "@peersyst/react-native-components";
import styled from "@peersyst/react-native-styled";
import DAppWebView from "module/signer/containers/DAppWebView/DAppWebView";

export const BrowserScreenRoot = styled(Col)(({ theme }) => ({
flex: 1,
backgroundColor: theme.palette.background,
}));

export const BrowserScreenWebView = styled(DAppWebView)(({ theme }) => ({
backgroundColor: theme.palette.background,
}));

export const BrowserScreenLoadingContainer = styled(Col)(({ theme }) => ({
alignItems: "center",
justifyContent: "center",
backgroundColor: theme.palette.background,
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: "100%",
}));
26 changes: 14 additions & 12 deletions src/module/dapp/screen/BrowserScreen/BrowserScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import { BrowserScreenRoot } from "./BrowserScreen.styles";
import { BrowserScreenLoadingContainer, BrowserScreenRoot, BrowserScreenWebView } from "./BrowserScreen.styles";
import { useBrowserScreen } from "./hooks/useBrowserScreen";
import BrowserScreenHeader from "./BrowserScreenHeader/BrowserScreenHeader";
import DAppWebView from "module/signer/containers/DAppWebView/DAppWebView";
import { useEffect, useState } from "react";
import { LoadingLogo } from "module/common/component/feedback/LoadingLogo/LoadingLogo";
import { Col } from "@peersyst/react-native-components";

const BrowserScreen = (): JSX.Element => {
const { headerProps, webviewProps } = useBrowserScreen();

// Workaround to ensure the screen infers the correct height without the header
const [isLoaded, setIsLoaded] = useState(false);
const [isWebViewLoaded, setIsWebViewLoaded] = useState(false);

useEffect(() => {
setTimeout(() => {
setIsLoaded(true);
}, 250);
}, 500);
}, []);

return (
<BrowserScreenRoot>
{isLoaded ? (
<>
<BrowserScreenHeader {...headerProps} />
<DAppWebView {...webviewProps} />
</>
) : (
<></>
)}
<BrowserScreenHeader {...headerProps} />
<Col flex={1}>
{isLoaded && <BrowserScreenWebView onLoadEnd={() => setIsWebViewLoaded(true)} {...webviewProps} />}
{(!isLoaded || !isWebViewLoaded) && (
<BrowserScreenLoadingContainer>
<LoadingLogo />
</BrowserScreenLoadingContainer>
)}
</Col>
</BrowserScreenRoot>
);
};
Expand Down
Loading