Skip to content

Commit

Permalink
sign email subscription modal
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya Smiyukha committed Jul 19, 2023
1 parent 91a3bd3 commit c25671c
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ApiPromise, WsProvider } from '@polkadot/api'
import React, { useEffect } from 'react'

import { useMyAccounts } from '@/accounts/hooks/useMyAccounts'
Expand All @@ -14,31 +13,27 @@ import { EmailSubscriptionMachine } from './machine'
import { EmailSubscriptionForm } from './types'

export const EmailSubscriptionModal = () => {
const provider = new WsProvider(process.env.REACT_APP_TESTNET_NODE_SOCKET)
const api = new ApiPromise({ provider })
const {
hideModal,
modalData: { member },
} = useModal<EmailSubscriptionModalCall>()

const { wallet } = useMyAccounts()

const [state, send] = useMachine(EmailSubscriptionMachine)

const signEmail = async () => {
if (state.context.email) {
await api.setSigner(wallet?.signer)
await api.sign(member.controllerAccount, {
data: state.context.email,
const timestamp = Date.now()
const signature = await wallet?.signer.signPayload({
address: member.controllerAccount,
data: `${member.id}:${timestamp}`
})
}
console.log(signature)
return signature
}

useEffect(() => {
if (state.matches('signature')) {
signEmail()
// const timestamp = new Date()
// const signature = api?.sign(member.controllerAccount, `${member.id}:${timestamp}`)
}
}, [state])

Expand Down

0 comments on commit c25671c

Please sign in to comment.