From 2969b7a2a588ec51565fae1b2b5a7fcf6ffd1f90 Mon Sep 17 00:00:00 2001 From: tiero <3596602+tiero@users.noreply.github.com> Date: Tue, 21 Feb 2023 19:59:45 +0100 Subject: [PATCH] add delegate button --- example/index.tsx | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/example/index.tsx b/example/index.tsx index bef6b5c..034fa8e 100644 --- a/example/index.tsx +++ b/example/index.tsx @@ -25,6 +25,7 @@ const App = () => { const [getPublicKeyReply, setGetPublicKeyReply] = useState(''); const [eventWithSig, setEvent] = useState({}); const [schnorrSig, setSchnorrSig] = useState(''); + const [delegationSig, setDelegateSig] = useState(''); useEffect(() => { (async () => { @@ -104,7 +105,34 @@ const App = () => { } catch (error) { console.error(error); } + } + const delegate = async () => { + try { + if (pubkey.length === 0) return; + + const connect = new Connect({ + secretKey, + target: pubkey, + }); + + const sig = await connect.rpc.call({ + target: pubkey, + request: { + method: 'delegate', + params: [ + getPublicKey(secretKey), + { + kind: 0, + until: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 365, + } + ], + } + }); + setDelegateSig(sig); + } catch (error) { + console.error(error); + } } const isConnected = () => { @@ -211,6 +239,21 @@ const App = () => { /> } +