-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Anonymous Login in Certain Chats #476
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7ad7a21
Remove continue anonymously for certain chats
teodorus-nathaniel b8f468b
Add login functionality before doing tx if without anon login
teodorus-nathaniel 1dd9d7e
Fix wrong var used
teodorus-nathaniel 4cc1b88
Fix issue if user logs in using account with 0 energy when sending flow
teodorus-nathaniel 6084473
Do not open cta modal if opening login modal
teodorus-nathaniel c3ac9c6
Fix wrong logic
teodorus-nathaniel b9814ed
Remove unused function
teodorus-nathaniel 6d23718
Change CHAT_IDS_WITHOUT_ANON_LOGIN_OPTIONS
olehmell 1dd89d1
Rename hooks
teodorus-nathaniel 9f8f7e7
Merge branch 'deploy/remove-anon' of https://github.com/dappforce/gri…
teodorus-nathaniel 880980c
Fix wrong var used
teodorus-nathaniel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { getChatIdsWithoutAnonLoginOptions } from '@/constants/chat' | ||
import { useLoginModal } from '@/stores/login-modal' | ||
import { useMyAccount } from '@/stores/my-account' | ||
import { generateManuallyTriggeredPromise } from '@/utils/promise' | ||
import { getIdFromSlug } from '@/utils/slug' | ||
import { useRouter } from 'next/router' | ||
import { useCallback, useEffect, useRef } from 'react' | ||
|
||
export default function useWithoutAnonLoginOptions() { | ||
const { query } = useRouter() | ||
const chatId = | ||
typeof query.slug === 'string' ? getIdFromSlug(query.slug) : undefined | ||
const withoutAnonLoginOptions = getChatIdsWithoutAnonLoginOptions().includes( | ||
chatId ?? '' | ||
) | ||
|
||
const isOpen = useLoginModal((state) => state.isOpen) | ||
const waitingLoginResolvers = useRef<VoidFunction[]>([]) | ||
useEffect(() => { | ||
if (!isOpen) { | ||
waitingLoginResolvers.current.forEach((resolver) => resolver()) | ||
waitingLoginResolvers.current = [] | ||
} | ||
}, [isOpen]) | ||
|
||
const setIsOpen = useLoginModal((state) => state.setIsOpen) | ||
|
||
const promptUserForLogin = useCallback(async () => { | ||
setIsOpen(true) | ||
const { getPromise, getResolver } = generateManuallyTriggeredPromise() | ||
waitingLoginResolvers.current.push(getResolver()) | ||
await getPromise() | ||
return useMyAccount.getState().address | ||
}, [setIsOpen]) | ||
|
||
return { withoutAnonLoginOptions, promptUserForLogin } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { create } from './utils' | ||
|
||
type State = { | ||
isOpen: boolean | ||
} | ||
|
||
type Actions = { | ||
setIsOpen: (isOpen: boolean) => void | ||
} | ||
|
||
const initialState: State = { | ||
isOpen: false, | ||
} | ||
|
||
export const useLoginModal = create<State & Actions>()((set) => ({ | ||
...initialState, | ||
setIsOpen: (isOpen) => { | ||
set({ isOpen }) | ||
}, | ||
})) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to useLoginOptions
and return
isLoginRequired
promptUserForLogin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future it will be main option, so better call it more generic I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to isNonAnonLoginRequired
because isLoginRequired is pretty ambiguous to me