Skip to content

Commit

Permalink
ENR Share button for mobile (#195)
Browse files Browse the repository at this point in the history
Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com>
  • Loading branch information
ScottyPoi and acolytec3 authored Apr 12, 2022
1 parent 629d22c commit e47160b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/browser-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@babel/preset-react": "^7.16.7",
"@babel/preset-typescript": "^7.16.7",
"@capacitor/cli": "^3.4.3",
"@capacitor/share": "1.1.2",
"@types/node": "^17.0.23",
"@types/react": "^17.0.43",
"@types/react-dom": "^17.0.14",
Expand Down
35 changes: 29 additions & 6 deletions packages/browser-client/src/Components/DevTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
useToast,
} from '@chakra-ui/react'
import { HistoryNetworkContentKeyUnionType, PortalNetwork, SubNetworkIds } from 'portalnetwork'
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'
import { ContentManager } from './ContentManager'
import { Share } from '@capacitor/share'

interface DevToolsProps {
portal: PortalNetwork | undefined
Expand All @@ -25,6 +26,7 @@ interface DevToolsProps {

export default function DevTools(props: DevToolsProps) {
const portal = props.portal
const [canShare, setCanShare] = useState(false)
const peers = props.peers.map((p) => {
return p.nodeId
})
Expand All @@ -35,6 +37,13 @@ export default function DevTools(props: DevToolsProps) {
const handlePing = (nodeId: string) => {
portal?.sendPing(nodeId, SubNetworkIds.HistoryNetwork)
}
async function share() {
await Share.share({
title: `Ultralight ENR`,
text: props.enr,
dialogTitle: `Share ENR`,
})
}

const handleFindNodes = (nodeId: string) => {
portal?.sendFindNodes(
Expand Down Expand Up @@ -68,12 +77,26 @@ export default function DevTools(props: DevToolsProps) {
})
}

async function sharing() {
const s = await Share.canShare()
setCanShare(s.value)
}

useEffect(() => {
sharing()
}, [])

return (
<VStack mt="10px">
<Heading size="sm">Network Tools</Heading>
<Button isDisabled={!portal} onClick={async () => handleCopy()} width={'100%'}>
COPY ENR
</Button>
<VStack>
{canShare ? (
<Button width={`100%`} onClick={share}>
SHARE ENR
</Button>
) : (
<Button onClick={async () => handleCopy()} width={'100%'}>
COPY ENR
</Button>
)}
<ContentManager portal={portal} />
<Divider />
<Heading size="sm">Peer Tools</Heading>
Expand Down

0 comments on commit e47160b

Please sign in to comment.