Skip to content

Commit

Permalink
feat: add mobile universal link button (#186)
Browse files Browse the repository at this point in the history
* feat: add mobile universal link button

* chore: move the button to white listed route

* fix: remove https from url param

* chore: add url input

* chore: improve link handling and wording
  • Loading branch information
fedeerbes authored Oct 16, 2024
1 parent ee09c35 commit e1e6a02
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
8 changes: 7 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { GetAddresses } from './components/bitcoin/GetAddresses.tsx';
import { SendBtc } from './components/bitcoin/SendBtc';
import EtchRunes from './components/EtchRunes';
import MintRunes from './components/MintRunes';
import { MobileUniversalLink } from './components/mobile/universalLink.tsx';
import { NetworkSelector } from './components/NetworkSelector';
import { SendSip10 } from './components/stacks/SendSip10';
import { SendStx } from './components/stacks/SendStx';
Expand All @@ -49,6 +50,8 @@ const ConnectionContext = createContext<{

const useConnectionContext = () => useContext(ConnectionContext);

const whiteListedPaths = ['/mobile-universal-link'];

function AppWithProviders({ children }: React.PropsWithChildren<{}>) {
const queryClient = useQueryClient();
const [network, setNetwork] = useLocalStorage<BitcoinNetworkType>(
Expand All @@ -60,6 +63,8 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) {

const isConnected = btcAddressInfo.length + stxAddressInfo.length > 0;

const isWhiteListedPath = whiteListedPaths.includes(window.location.pathname);

const clearAppData = useCallback(() => {
setBtcAddressInfo([]);
setStxAddressInfo([]);
Expand Down Expand Up @@ -138,7 +143,7 @@ function AppWithProviders({ children }: React.PropsWithChildren<{}>) {
[network, btcAddressInfo, stxAddressInfo, onDisconnect],
);

if (!isConnected) {
if (!isConnected && !isWhiteListedPath) {
return (
<Container>
<Header>
Expand Down Expand Up @@ -244,6 +249,7 @@ const router = createBrowserRouter(
<Route index element={<WalletMethods />} />
<Route path="bitcoin-methods" element={<BitcoinMethods />} />
<Route path="stacks-methods" element={<StacksMethods />} />
<Route path="mobile-universal-link" element={<MobileUniversalLink />} />
<Route path="*" element={<NoMatch />} />
</Route>,
),
Expand Down
31 changes: 31 additions & 0 deletions example/src/components/mobile/universalLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useState } from 'react';
import { Button, Card, Input } from '../../App.styles';

export function MobileUniversalLink() {
const [url, setUrl] = useState('wallet.xverse.app/explore');

const link = `https://connect.xverse.app/browser?url=${url}`;

const handleClick = () => {
window.open(link, '_blank', 'noopener,noreferrer');
};

return (
<Card>
<h3>Mobile App Universal Link</h3>
<div>
If Xverse app is installed, it will open the browser withing the app using the url param
</div>
<div>If Xverse app is not installed, it will prompt the user to install the app</div>
<div style={{ marginTop: 15, marginBottom: 15 }}>
<div>Url param</div>
<Input type="text" value={url} onChange={(e) => setUrl(e.target.value)} />
</div>
<div style={{ marginTop: 15, marginBottom: 15 }}>
<div>Full link</div>
<div>{link}</div>
</div>
<Button onClick={handleClick}>Use Universal Link</Button>
</Card>
);
}
5 changes: 5 additions & 0 deletions example/src/layouts/CollapseDesktop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export function CollapseDesktop({ children }: React.PropsWithChildren<{}>) {
label: 'Stacks Methods',
href: '/stacks-methods',
},
{
icon: 'home',
label: 'Mobile Universal Link',
href: '/mobile-universal-link',
},
].map(({ label, href }) => (
<NavLink key={href} href={href} label={label} />
))}
Expand Down

0 comments on commit e1e6a02

Please sign in to comment.