@@ -13,8 +13,9 @@ import {
13
13
useToast ,
14
14
} from '@chakra-ui/react'
15
15
import { HistoryNetworkContentKeyUnionType , PortalNetwork , SubNetworkIds } from 'portalnetwork'
16
- import React , { useState } from 'react'
16
+ import React , { useEffect , useState } from 'react'
17
17
import { ContentManager } from './ContentManager'
18
+ import { Share } from '@capacitor/share'
18
19
19
20
interface DevToolsProps {
20
21
portal : PortalNetwork | undefined
@@ -25,6 +26,7 @@ interface DevToolsProps {
25
26
26
27
export default function DevTools ( props : DevToolsProps ) {
27
28
const portal = props . portal
29
+ const [ canShare , setCanShare ] = useState ( false )
28
30
const peers = props . peers . map ( ( p ) => {
29
31
return p . nodeId
30
32
} )
@@ -35,6 +37,13 @@ export default function DevTools(props: DevToolsProps) {
35
37
const handlePing = ( nodeId : string ) => {
36
38
portal ?. sendPing ( nodeId , SubNetworkIds . HistoryNetwork )
37
39
}
40
+ async function share ( ) {
41
+ await Share . share ( {
42
+ title : `Ultralight ENR` ,
43
+ text : props . enr ,
44
+ dialogTitle : `Share ENR` ,
45
+ } )
46
+ }
38
47
39
48
const handleFindNodes = ( nodeId : string ) => {
40
49
portal ?. sendFindNodes (
@@ -68,12 +77,26 @@ export default function DevTools(props: DevToolsProps) {
68
77
} )
69
78
}
70
79
80
+ async function sharing ( ) {
81
+ const s = await Share . canShare ( )
82
+ setCanShare ( s . value )
83
+ }
84
+
85
+ useEffect ( ( ) => {
86
+ sharing ( )
87
+ } , [ ] )
88
+
71
89
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
+ ) }
77
100
< ContentManager portal = { portal } />
78
101
< Divider />
79
102
< Heading size = "sm" > Peer Tools</ Heading >
0 commit comments