Skip to content
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
20 changes: 9 additions & 11 deletions packages/browser-sdk/src/providers/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,18 @@ export class InjectedProvider implements Provider {
});
}

if (this.addressTypes.includes(AddressType.solana)) {
if (this.selectedWalletId !== "phantom") {
if (!this.walletRegistry.has(requestedWalletId)) {
debug.error(DebugCategory.INJECTED_PROVIDER, "Unknown injected wallet id requested", {
walletId: requestedWalletId,
});
throw new Error(`Unknown injected wallet id: ${requestedWalletId}`);
}

this.selectedWalletId = requestedWalletId;
debug.log(DebugCategory.INJECTED_PROVIDER, "Selected injected wallet for connection", {
if (this.addressTypes.includes(AddressType.solana) && this.selectedWalletId !== "phantom") {
if (!this.walletRegistry.has(requestedWalletId)) {
debug.error(DebugCategory.INJECTED_PROVIDER, "Unknown injected wallet id requested", {
walletId: requestedWalletId,
});
throw new Error(`Unknown injected wallet id: ${requestedWalletId}`);
}

this.selectedWalletId = requestedWalletId;
debug.log(DebugCategory.INJECTED_PROVIDER, "Selected injected wallet for connection", {
walletId: requestedWalletId,
});
}

this.emit("connect_start", {
Expand Down
16 changes: 0 additions & 16 deletions packages/react-native-sdk/src/ModalProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,6 @@ describe("ModalProvider", () => {
expect(getByTestId("modal")).toBeTruthy();
});

it("should pass isConnected prop to Modal", () => {
mockUsePhantom.mockReturnValue({
...mockUsePhantom(),
isConnected: true,
} as any);

const { getByTestId } = render(
<ModalProvider>
<mock-child />
</ModalProvider>,
);

const modal = getByTestId("modal");
expect(modal.props.isConnected).toBe(true);
});

it("should render ConnectModalContent when not connected", () => {
const { getByTestId } = render(
<ModalProvider>
Expand Down
9 changes: 1 addition & 8 deletions packages/react-native-sdk/src/ModalProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ export function ModalProvider({ children, appIcon, appName }: ModalProviderProps
return (
<ModalContext.Provider value={modalContextValue}>
{children}
<Modal
isVisible={isModalOpen}
onClose={closeModal}
appIcon={appIcon}
appName={appName}
isConnected={isConnected}
isMobile={true}
>
<Modal isVisible={isModalOpen} onClose={closeModal} appIcon={appIcon} appName={appName} isMobile={true}>
{isConnected ? (
<ConnectedModalContent onClose={closeModal} />
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jest.mock("../hooks/useConnect");
/* eslint-disable @typescript-eslint/no-var-requires */
jest.mock("@phantom/wallet-sdk-ui", () => {
const React = require("react");
const { View, Text } = require("react-native");
const { View, Text, TouchableOpacity } = require("react-native");

return {
...jest.requireActual("@phantom/wallet-sdk-ui"),
Expand All @@ -36,8 +36,35 @@ jest.mock("@phantom/wallet-sdk-ui", () => {
Icon: ({ type }: { type: string }) => {
return <View testID={`icon-${type}`} />;
},
Text: ({ children }: { children: React.ReactNode }) => {
return <Text>{children}</Text>;
Text: ({ children, style }: { children: React.ReactNode; style?: any }) => {
return <Text style={style}>{children}</Text>;
},
ModalHeader: ({
title,
onClose,
goBack,
onGoBack,
}: {
title: string;
onClose?: () => void;
goBack?: boolean;
onGoBack?: () => void;
}) => {
return (
<View testID="modal-header">
{goBack && onGoBack && (
<TouchableOpacity testID="modal-header-back" onPress={onGoBack}>
<Text>Back</Text>
</TouchableOpacity>
)}
<Text testID="modal-header-title">{title}</Text>
{onClose && (
<TouchableOpacity testID="modal-header-close" onPress={onClose}>
<Text>×</Text>
</TouchableOpacity>
)}
</View>
);
},
};
});
Expand Down
30 changes: 28 additions & 2 deletions packages/react-native-sdk/src/components/ConnectModalContent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useCallback } from "react";
import { View, Image, StyleSheet, ActivityIndicator } from "react-native";
import type { EmbeddedProviderAuthType } from "@phantom/embedded-provider-core";
import { Button, Icon, Text, useTheme, hexToRgba } from "@phantom/wallet-sdk-ui";
import { Button, Icon, Text, useTheme, hexToRgba, ModalHeader } from "@phantom/wallet-sdk-ui";
import { usePhantom } from "../PhantomContext";
import { useConnect } from "../hooks/useConnect";

Expand Down Expand Up @@ -51,18 +51,21 @@ export function ConnectModalContent({ appIcon, onClose }: ConnectModalContentPro
appIcon: {
borderRadius: 28,
height: 56,
marginBottom: 12,
width: 56,
},
buttonContainer: {
alignItems: "center",
flexDirection: "column",
gap: 12,
paddingHorizontal: 32,
width: "100%",
},
container: {
alignItems: "center",
flexDirection: "column",
gap: 24,
gap: 12,
paddingBottom: 24,
width: "100%",
},
errorContainer: {
Expand All @@ -77,6 +80,17 @@ export function ConnectModalContent({ appIcon, onClose }: ConnectModalContentPro
color: errorTextColor,
fontSize: 14,
},
footer: {
alignItems: "center",
borderColor: theme.aux,
borderTopWidth: 1,
flexDirection: "row",
gap: 4,
justifyContent: "center",
marginTop: 24,
padding: 16,
width: "100%",
},
loadingContainer: {
alignItems: "center",
flexDirection: "column",
Expand All @@ -91,6 +105,8 @@ export function ConnectModalContent({ appIcon, onClose }: ConnectModalContentPro

return (
<View style={styles.container}>
<ModalHeader title="Login or Sign Up" onClose={onClose} />

{appIcon && <Image testID="app-icon" source={{ uri: appIcon }} style={styles.appIcon} />}

{error && (
Expand Down Expand Up @@ -166,6 +182,16 @@ export function ConnectModalContent({ appIcon, onClose }: ConnectModalContentPro
)}
</View>
)}

<View style={styles.footer}>
<Text variant="label" color={theme.secondary}>
Powered by
</Text>
<Icon type="phantom" size={16} color={theme.secondary} />
<Text variant="label" color={theme.secondary}>
Phantom
</Text>
</View>
</View>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jest.mock("../hooks/useDisconnect");
/* eslint-disable @typescript-eslint/no-var-requires */
jest.mock("@phantom/wallet-sdk-ui", () => {
const React = require("react");
const { TouchableOpacity, Text } = require("react-native");
const { TouchableOpacity, Text, View } = require("react-native");

return {
...jest.requireActual("@phantom/wallet-sdk-ui"),
Expand Down Expand Up @@ -41,8 +41,39 @@ jest.mock("@phantom/wallet-sdk-ui", () => {
</TouchableOpacity>
);
},
Text: ({ children, variant }: { children: React.ReactNode; variant?: string }) => {
return <Text testID={variant}>{children}</Text>;
Text: ({ children, variant, style }: { children: React.ReactNode; variant?: string; style?: any }) => {
return (
<Text testID={variant} style={style}>
{children}
</Text>
);
},
ModalHeader: ({
title,
onClose,
goBack,
onGoBack,
}: {
title: string;
onClose?: () => void;
goBack?: boolean;
onGoBack?: () => void;
}) => {
return (
<View testID="modal-header">
{goBack && onGoBack && (
<TouchableOpacity testID="modal-header-back" onPress={onGoBack}>
<Text>Back</Text>
</TouchableOpacity>
)}
<Text testID="modal-header-title">{title}</Text>
{onClose && (
<TouchableOpacity testID="modal-header-close" onPress={onClose}>
<Text>×</Text>
</TouchableOpacity>
)}
</View>
);
},
hexToRgba: (_hex: string, opacity: number) => `rgba(255, 0, 0, ${opacity})`,
};
Expand Down
16 changes: 13 additions & 3 deletions packages/react-native-sdk/src/components/ConnectedModalContent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from "react";
import { View, StyleSheet } from "react-native";
import { Button, Text, useTheme, hexToRgba } from "@phantom/wallet-sdk-ui";
import { Button, Text, useTheme, hexToRgba, ModalHeader } from "@phantom/wallet-sdk-ui";
import { usePhantom } from "../PhantomContext";
import { useDisconnect } from "../hooks/useDisconnect";

Expand Down Expand Up @@ -54,6 +54,14 @@ export function ConnectedModalContent({ onClose }: ConnectedModalContentProps) {
addressText: {
fontFamily: "monospace",
},
container: {
alignItems: "center",
flexDirection: "column",
gap: 24,
paddingBottom: 24,
paddingHorizontal: 32,
width: "100%",
},
errorContainer: {
backgroundColor: errorBackgroundColor,
borderColor: errorBorderColor,
Expand All @@ -65,7 +73,9 @@ export function ConnectedModalContent({ onClose }: ConnectedModalContentProps) {
});

return (
<>
<View style={styles.container}>
<ModalHeader title="Wallet" onClose={onClose} />

{addresses && addresses.length > 0 && (
<View style={styles.accountList}>
{addresses.map((account, index) => (
Expand All @@ -92,6 +102,6 @@ export function ConnectedModalContent({ onClose }: ConnectedModalContentProps) {
<Button onClick={handleDisconnect} disabled={isDisconnecting} isLoading={isDisconnecting} fullWidth>
<Text variant="captionBold">{isDisconnecting ? "Disconnecting..." : "Disconnect"}</Text>
</Button>
</>
</View>
);
}
38 changes: 0 additions & 38 deletions packages/react-native-sdk/src/components/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,6 @@ describe("Modal Component", () => {
expect(container).toBeTruthy();
});

it("should render the close button", () => {
const { getByTestId } = renderModal();
expect(() => getByTestId("icon-close")).not.toThrow();
});

it("should render the correct header text when not connected", () => {
const { getByText } = renderModal({ isConnected: false });
expect(getByText("Login or Sign Up")).toBeTruthy();
});

it("should render the correct header text when connected", () => {
const { getByText } = renderModal({ isConnected: true });
expect(getByText("Wallet")).toBeTruthy();
});

it("should render the Phantom branding in the footer", () => {
const { getByText, getByTestId } = renderModal();
expect(getByText("Powered by")).toBeTruthy();
expect(getByText("Phantom")).toBeTruthy();
expect(() => getByTestId("icon-phantom")).not.toThrow();
});

it("should render children content", () => {
const { getByTestId, getByText } = renderModal();
expect(getByTestId("modal-child")).toBeTruthy();
Expand All @@ -111,14 +89,6 @@ describe("Modal Component", () => {
});
});

describe("Interactions", () => {
it("should have a close button", () => {
const { getByTestId } = renderModal();
const closeIcon = getByTestId("icon-close");
expect(closeIcon).toBeTruthy();
});
});

describe("Styling", () => {
it("should render with bottom sheet styling", () => {
// Modal uses StyleSheet.create with theme colors and proper positioning
Expand All @@ -135,12 +105,4 @@ describe("Modal Component", () => {
expect(container).toBeTruthy();
});
});

describe("Accessibility", () => {
it("should have an accessible close button", () => {
const { getByTestId } = renderModal();
const closeIcon = getByTestId("icon-close");
expect(closeIcon).toBeTruthy();
});
});
});
Loading