Skip to content

Commit

Permalink
fix: WalletConnect on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
hachiojidev committed Jul 15, 2021
1 parent 0412a66 commit 5a3a25d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
19 changes: 1 addition & 18 deletions packages/pancake-uikit/src/widgets/WalletModal/ConnectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@ const WalletWrapper = styled(Box)`

const sortedConfig = config.sort((a, b) => a.priority - b.priority);

/**
* Trust Wallet is not supported on iOS. Default to Wallet Connect
*/
const getSupportedWallet = (wallet: Config) => {
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;

if (wallet.title === "Trust Wallet" && isIOS) {
const walletConnect = config.find((configItem) => configItem.title === "WalletConnect");

if (walletConnect) {
return walletConnect;
}
}

return wallet;
};

const ConnectModal: React.FC<Props> = ({ login, onDismiss = () => null, displayCount = 3 }) => {
const [showMore, setShowMore] = useState(false);
const theme = useTheme();
Expand All @@ -58,7 +41,7 @@ const ConnectModal: React.FC<Props> = ({ login, onDismiss = () => null, displayC
<Grid gridTemplateColumns="1fr 1fr" gridGap="8px">
{displayListConfig.map((wallet) => (
<Box key={wallet.title}>
<WalletCard walletConfig={getSupportedWallet(wallet)} login={login} onDismiss={onDismiss} />
<WalletCard walletConfig={wallet} login={login} onDismiss={onDismiss} />
</Box>
))}
{!showMore && <MoreWalletCard onClick={() => setShowMore(true)} />}
Expand Down
12 changes: 10 additions & 2 deletions packages/pancake-uikit/src/widgets/WalletModal/WalletCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Text from "../../components/Text/Text";
import MoreHoriz from "../../components/Svg/Icons/MoreHoriz";
import { ButtonProps } from "../../components/Button";
import { connectorLocalStorageKey } from "./config";
import { Login, Config } from "./types";
import { Login, Config, ConnectorNames } from "./types";

interface Props {
walletConfig: Config;
Expand Down Expand Up @@ -40,7 +40,15 @@ const WalletCard: React.FC<Props> = ({ login, walletConfig, onDismiss }) => {
<WalletButton
variant="tertiary"
onClick={() => {
login(walletConfig.connectorId);
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;

// Since iOS does not support Trust Wallet we fall back to WalletConnect
if (walletConfig.title === "Trust Wallet" && isIOS) {
login(ConnectorNames.WalletConnect);
} else {
login(walletConfig.connectorId);
}

window.localStorage.setItem(connectorLocalStorageKey, walletConfig.connectorId);
onDismiss();
}}
Expand Down

0 comments on commit 5a3a25d

Please sign in to comment.