Skip to content

Commit

Permalink
ENG-4064 fix(portal): remove timeout from create identity (#846)
Browse files Browse the repository at this point in the history
## Affected Packages

Apps

- [x] portal

Packages

- [ ] 1ui
- [ ] api
- [ ] protocol
- [ ] sdk

Tools

- [ ] tools

## Overview

- Removes the timeout from the create identity form as it is no longer
needed after updates were made to handle IPFS timeout on backend.

## Screen Captures

If applicable, add screenshots or screen captures of your changes.

## Declaration

- [x] I hereby declare that I have abided by the rules and regulations
as outlined in the
[CONTRIBUTING.md](https://github.com/0xIntuition/intuition-ts/blob/main/CONTRIBUTING.md)
  • Loading branch information
Vitalsine85 authored Sep 17, 2024
1 parent 47c9394 commit 21d6a6a
Showing 1 changed file with 3 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,53 +276,6 @@ function CreateIdentityForm({

const [formTouched, setFormTouched] = useState(false) // to disable submit if user hasn't touched form yet

const submitWithTimeout = (
formData: FormData,
): Promise<IdentityPresenter> => {
return new Promise((resolve, reject) => {
const maxAttempts = 30 // 30 seconds total
let attempts = 0

const checkSubmissionStatus = () => {
if (offChainFetcher.state === 'idle') {
if (offChainFetcher.data) {
if (offChainFetcher.data.success === 'error') {
// If there's an error in the response, reject with that error
reject(
new Error(
offChainFetcher.data.error || 'Unknown error occurred',
),
)
} else if (offChainFetcher.data.identity) {
// If we have the identity data, resolve with it
resolve(offChainFetcher.data.identity)
} else {
// If we don't have an error or identity data, something went wrong
reject(new Error('Invalid response data'))
}
} else if (attempts >= maxAttempts) {
reject(new Error('Submission timed out'))
} else {
attempts++
setTimeout(checkSubmissionStatus, 1000) // Check every second
}
} else if (attempts >= maxAttempts) {
reject(new Error('Submission timed out'))
} else {
attempts++
setTimeout(checkSubmissionStatus, 1000) // Check every second
}
}

offChainFetcher.submit(formData, {
action: '/actions/create-identity',
method: 'post',
})

checkSubmissionStatus()
})
}

const handleSubmit = async () => {
try {
if (walletClient) {
Expand Down Expand Up @@ -359,13 +312,9 @@ function CreateIdentityForm({
try {
logger('try offline submit')
dispatch({ type: 'PUBLISHING_IDENTITY' })
const createdIdentity = await submitWithTimeout(formData)

// If we reach here, the offchain submission was successful
// Now we can proceed with the onchain transaction
setTransactionResponseData(createdIdentity)
await handleOnChainCreateIdentity({
atomData: createdIdentity.identity_id,
offChainFetcher.submit(formData, {
action: '/actions/create-identity',
method: 'post',
})
} catch (error: unknown) {
handleSubmitError(error)
Expand Down

0 comments on commit 21d6a6a

Please sign in to comment.