Skip to content

Commit e47160b

Browse files
ScottyPoiacolytec3
andauthored
ENR Share button for mobile (#195)
Co-authored-by: acolytec3 <[email protected]>
1 parent 629d22c commit e47160b

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

packages/browser-client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@babel/preset-react": "^7.16.7",
2020
"@babel/preset-typescript": "^7.16.7",
2121
"@capacitor/cli": "^3.4.3",
22+
"@capacitor/share": "1.1.2",
2223
"@types/node": "^17.0.23",
2324
"@types/react": "^17.0.43",
2425
"@types/react-dom": "^17.0.14",

packages/browser-client/src/Components/DevTools.tsx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import {
1313
useToast,
1414
} from '@chakra-ui/react'
1515
import { HistoryNetworkContentKeyUnionType, PortalNetwork, SubNetworkIds } from 'portalnetwork'
16-
import React, { useState } from 'react'
16+
import React, { useEffect, useState } from 'react'
1717
import { ContentManager } from './ContentManager'
18+
import { Share } from '@capacitor/share'
1819

1920
interface DevToolsProps {
2021
portal: PortalNetwork | undefined
@@ -25,6 +26,7 @@ interface DevToolsProps {
2526

2627
export default function DevTools(props: DevToolsProps) {
2728
const portal = props.portal
29+
const [canShare, setCanShare] = useState(false)
2830
const peers = props.peers.map((p) => {
2931
return p.nodeId
3032
})
@@ -35,6 +37,13 @@ export default function DevTools(props: DevToolsProps) {
3537
const handlePing = (nodeId: string) => {
3638
portal?.sendPing(nodeId, SubNetworkIds.HistoryNetwork)
3739
}
40+
async function share() {
41+
await Share.share({
42+
title: `Ultralight ENR`,
43+
text: props.enr,
44+
dialogTitle: `Share ENR`,
45+
})
46+
}
3847

3948
const handleFindNodes = (nodeId: string) => {
4049
portal?.sendFindNodes(
@@ -68,12 +77,26 @@ export default function DevTools(props: DevToolsProps) {
6877
})
6978
}
7079

80+
async function sharing() {
81+
const s = await Share.canShare()
82+
setCanShare(s.value)
83+
}
84+
85+
useEffect(() => {
86+
sharing()
87+
}, [])
88+
7189
return (
72-
<VStack mt="10px">
73-
<Heading size="sm">Network Tools</Heading>
74-
<Button isDisabled={!portal} onClick={async () => handleCopy()} width={'100%'}>
75-
COPY ENR
76-
</Button>
90+
<VStack>
91+
{canShare ? (
92+
<Button width={`100%`} onClick={share}>
93+
SHARE ENR
94+
</Button>
95+
) : (
96+
<Button onClick={async () => handleCopy()} width={'100%'}>
97+
COPY ENR
98+
</Button>
99+
)}
77100
<ContentManager portal={portal} />
78101
<Divider />
79102
<Heading size="sm">Peer Tools</Heading>

0 commit comments

Comments
 (0)