Skip to content

Commit

Permalink
Merge pull request #511 from dappforce/fix/login
Browse files Browse the repository at this point in the history
Fix issue for login prompt when sending messages
  • Loading branch information
olehmell authored Dec 28, 2023
2 parents 8dcdb3e + 61403e4 commit 159c6e3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/chats/ChatForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Button, { ButtonProps } from '@/components/Button'
import TextArea, { TextAreaProps } from '@/components/inputs/TextArea'
import { ERRORS } from '@/constants/error'
import useAutofocus from '@/hooks/useAutofocus'
import useLoginOption from '@/hooks/useLoginOption'
import useRequestTokenAndSendMessage from '@/hooks/useRequestTokenAndSendMessage'
import { showErrorToast } from '@/hooks/useToastError'
import { useConfigContext } from '@/providers/ConfigProvider'
Expand All @@ -19,6 +20,7 @@ import {
getHasEnoughEnergy,
hasSentMessageStorage,
useMyAccount,
useMyMainAddress,
} from '@/stores/my-account'
import { cx } from '@/utils/class-names'
import { getOffchainPostingHubs } from '@/utils/env/client'
Expand Down Expand Up @@ -80,6 +82,7 @@ export default function ChatForm({
beforeMesageSend,
...props
}: ChatFormProps) {
const myAddress = useMyMainAddress()
const replyTo = useMessageData((state) => state.replyTo)
const messageToEdit = useMessageData((state) => state.messageToEdit)
const clearAction = useMessageData((state) => state.clearAction)
Expand Down Expand Up @@ -226,17 +229,14 @@ export default function ChatForm({
resetForm()
const isOffchainPosting = getOffchainPostingHubs().includes(hubId)
if (isOffchainPosting) {
resetForm()
sendOffchainMessage({
...messageParams,
uuid: crypto.randomUUID(),
timestamp: Date.now(),
})
} else if (shouldSendMessage) {
resetForm()
sendMessage(messageParams)
} else {
resetForm()
requestTokenAndSendMessage(messageParams)
setIsRequestingEnergy(true)
}
Expand All @@ -256,8 +256,14 @@ export default function ChatForm({
incrementMessageCount()
}

const { promptUserForLogin } = useLoginOption()
const submitForm = async (e?: SyntheticEvent) => {
e?.preventDefault()
if (!myAddress) {
promptUserForLogin()
return
}

handleSubmit()
}
const renderSendButton = (classNames: string) => (
Expand Down

0 comments on commit 159c6e3

Please sign in to comment.