From 91a3bd3ef9c7a36a03e6c6ffd8e791bd0174df7f Mon Sep 17 00:00:00 2001 From: ilya Smiyukha Date: Tue, 11 Jul 2023 15:24:48 +0200 Subject: [PATCH] signature for email modal --- .../EmailSubscriptionModal.tsx | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/memberships/modals/EmailSubscriptionModal/EmailSubscriptionModal.tsx b/packages/ui/src/memberships/modals/EmailSubscriptionModal/EmailSubscriptionModal.tsx index 6016bbf991..65dbdc7909 100644 --- a/packages/ui/src/memberships/modals/EmailSubscriptionModal/EmailSubscriptionModal.tsx +++ b/packages/ui/src/memberships/modals/EmailSubscriptionModal/EmailSubscriptionModal.tsx @@ -1,6 +1,7 @@ +import { ApiPromise, WsProvider } from '@polkadot/api' import React, { useEffect } from 'react' -// import { useApi } from '@/api/hooks/useApi' +import { useMyAccounts } from '@/accounts/hooks/useMyAccounts' import { FailureModal } from '@/common/components/FailureModal' import { ResultText } from '@/common/components/Modal' import { WaitModal } from '@/common/components/WaitModal' @@ -13,18 +14,31 @@ import { EmailSubscriptionMachine } from './machine' import { EmailSubscriptionForm } from './types' export const EmailSubscriptionModal = () => { - // const { api } = useApi() + const provider = new WsProvider(process.env.REACT_APP_TESTNET_NODE_SOCKET) + const api = new ApiPromise({ provider }) const { hideModal, modalData: { member }, } = useModal() + 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, + }) + } + } + useEffect(() => { if (state.matches('signature')) { + signEmail() // const timestamp = new Date() - // api?.sign(member.controllerAccount, `${member.id}:${timestamp}`) + // const signature = api?.sign(member.controllerAccount, `${member.id}:${timestamp}`) } }, [state])