-
Notifications
You must be signed in to change notification settings - Fork 5
feat: support user handles #468
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
Open
jeronimoalbi
wants to merge
41
commits into
main
Choose a base branch
from
feat/username-handle-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
30c1be6
feat: add protocol support for register, transfer and accept
jeronimoalbi ad49c3b
feat: add API endpoints for register, transfer and accept
jeronimoalbi cd6162d
feat: change handle register to remove previous handle
jeronimoalbi 32bada1
fix: correct issue in reader that led to always start from 1st block
jeronimoalbi 58aeae0
chore: remove one API URL from reader Docker compose file
jeronimoalbi d964956
feat: remove prepared statements and change code for consistency
jeronimoalbi 754e0f5
fix: remove previous handle transfer if it exists
jeronimoalbi 9cdf188
feat: support search posts by user handle
jeronimoalbi 9a468eb
feat: add user handle to feed, follow and post endpoints
jeronimoalbi 6b50ff7
feat: add user handle to posts endpoint
jeronimoalbi 62bcb9b
feat: add user handle display support protocol
jeronimoalbi 50c3dd4
feat: add display field to API endpoints
jeronimoalbi 39c2632
feat: add notification for registration of a user handle already taken
jeronimoalbi e356f0a
feat: add API endpoint to get user handle by name or address
jeronimoalbi 8464e85
refactor: change protocol names to be more explicit
jeronimoalbi f9cf2f7
chore: use uppercase for global consts
jeronimoalbi 9447752
refactor: change HandleTable name to AccountTable
jeronimoalbi bf956b9
refactor: update user handle protocol features for account table
jeronimoalbi 26ef719
feat: add notification when a handle is transfered to a user
jeronimoalbi 8e4e07c
Merge branch 'main' into feat/username-handle-support
jeronimoalbi f576d6b
fix: change Tiltfile to reload on code changes
jeronimoalbi ff9eb48
chore: change reader docker compose to use testnet API by default
jeronimoalbi eb2fef3
chore: update dockerignore
jeronimoalbi 25e0350
chore: allow requests to `https://*.allinbits.services`
jeronimoalbi 1a9cc2f
feat: change UI to render user handle when available
jeronimoalbi 4ea2887
feat: add tooltip to user address or handle
jeronimoalbi a94360d
refactor: change handle API endpoint to account
jeronimoalbi 278c79f
fix: correct issue with account API endpoint
jeronimoalbi 29025e3
chore: reduce handle length to 25 characters
jeronimoalbi 58fb139
feat: add `useAcount()` composable
jeronimoalbi 5686a5b
feat: add user handle to profile view and wallet connect button
jeronimoalbi df24fcf
chore: add missing import
jeronimoalbi ce50231
fix: correct following API endpoint issue with user handles
jeronimoalbi 60ff6c2
feat: add views and dialogs to register a new account handle
jeronimoalbi 8017c27
fix: correct TS issues
jeronimoalbi 2d589da
feat: change frontend to validate account handle registration
jeronimoalbi 1462ac5
chore: add handle name to the registration error notification
jeronimoalbi 6eedb03
chore: remove error when `useAccount()` fails to find an account
jeronimoalbi 090030d
feat: change handle to appear below account addresses
jeronimoalbi 4b2016f
fix: correct TS issues
jeronimoalbi f04a21b
feat: allow configuring the required fee to register a handle
jeronimoalbi 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
| import type { Gets } from '@atomone/dither-api-types'; | ||
|
|
||
| import { eq, or, sql } from 'drizzle-orm'; | ||
|
|
||
| import { getDatabase } from '../../drizzle/db'; | ||
| import { HandleTable } from '../../drizzle/schema'; | ||
|
|
||
| const statement = getDatabase() | ||
| .select({ | ||
| name: HandleTable.name, | ||
| address: HandleTable.address, | ||
| display: HandleTable.display, | ||
| }) | ||
| .from(HandleTable) | ||
| .where( | ||
| or( | ||
| eq(HandleTable.name, sql.placeholder('name')), | ||
| eq(HandleTable.address, sql.placeholder('address')), | ||
| ), | ||
| ) | ||
| .orderBy(HandleTable.name) | ||
| .limit(1) | ||
| .prepare('stmnt_get_handle'); | ||
|
|
||
| export async function Handle(query: Gets.HandleQuery) { | ||
| const { address, name } = query; | ||
| if (!address && !name) { | ||
| return { status: 400, error: 'handle name or address is required' }; | ||
| } | ||
|
|
||
| try { | ||
| const [handle] = await statement.execute({ address, name }); | ||
| if (!handle) { | ||
| return { status: 404, rows: [] }; | ||
| } | ||
|
|
||
| return { status: 200, rows: [handle] }; | ||
| } catch (error) { | ||
| console.error(error); | ||
| return { error: 'failed to read data from database' }; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
| import type { Posts } from '@atomone/dither-api-types'; | ||
|
|
||
| import type { DbClient } from '../../drizzle/db'; | ||
|
|
||
| import { and, eq } from 'drizzle-orm'; | ||
|
|
||
| import { getDatabase } from '../../drizzle/db'; | ||
| import { HandleTable, HandleTransferTable } from '../../drizzle/schema'; | ||
| import { lower } from '../utility'; | ||
|
|
||
| export async function AcceptHandle(body: Posts.AcceptHandleBody) { | ||
| const db = getDatabase(); | ||
| try { | ||
| if (!await doesTransferToAddressExists(db, body.handle, body.to_address)) { | ||
| return { status: 400, error: 'handle not found or not transferred to address' }; | ||
| } | ||
|
|
||
| await db | ||
| .update(HandleTable) | ||
| .set({ address: body.to_address.toLowerCase() }) | ||
| .where(eq(lower(HandleTable.name), body.handle.toLowerCase())); | ||
|
|
||
| return { status: 200 }; | ||
| } catch (err) { | ||
| console.error(err); | ||
| return { status: 400, error: 'failed to transfer handle' }; | ||
| } | ||
| } | ||
|
|
||
| async function doesTransferToAddressExists(db: DbClient, handle: string, address: string): Promise<boolean> { | ||
| const count = await db.$count(HandleTransferTable, and( | ||
| eq(lower(HandleTransferTable.name), handle.toLowerCase()), | ||
| eq(HandleTransferTable.to_address, address.toLowerCase()), | ||
| )); | ||
| return count !== 0; | ||
| } |
This file contains hidden or 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,44 @@ | ||
| import type { Posts } from '@atomone/dither-api-types'; | ||
|
|
||
| import { count, eq, sql } from 'drizzle-orm'; | ||
|
|
||
| import { getDatabase } from '../../drizzle/db'; | ||
| import { HandleTable } from '../../drizzle/schema'; | ||
| import { lower } from '../utility'; | ||
| import { MAX_DISPLAY_LENGTH } from './registerHandle'; | ||
|
|
||
| const handleAddressExistsStmt = getDatabase() | ||
| .select({ count: count() }) | ||
| .from(HandleTable) | ||
| .where(eq(lower(HandleTable.address), sql.placeholder('address'))) | ||
| .prepare('stmt_handle_address_exists'); | ||
|
|
||
| export async function DisplayHandle(body: Posts.DisplayHandleBody) { | ||
| const display = (body.display || '').trim(); | ||
| if (display.length > MAX_DISPLAY_LENGTH) { | ||
| return { status: 400, error: `maximum display length is ${MAX_DISPLAY_LENGTH} characters long` }; | ||
| } | ||
|
|
||
| const db = getDatabase(); | ||
| try { | ||
| const address = body.from.toLowerCase(); | ||
| if (!await hasHandle(address)) { | ||
| return { status: 400, error: 'account requires a handle to set a display text' }; | ||
| } | ||
|
|
||
| await db | ||
| .update(HandleTable) | ||
| .set({ display }) | ||
| .where(eq(HandleTable.address, address)); | ||
|
|
||
| return { status: 200 }; | ||
| } catch (err) { | ||
| console.error(err); | ||
| return { status: 400, error: 'failed to update display handle' }; | ||
| } | ||
| } | ||
|
|
||
| async function hasHandle(address: string): Promise<boolean> { | ||
| const [result] = await handleAddressExistsStmt.execute({ address }); | ||
| return (result?.count ?? 0) !== 0; | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| export * from './acceptHandle'; | ||
| export * from './auth'; | ||
| export * from './authCreate'; | ||
| export * from './dislike'; | ||
| export * from './displayHandle'; | ||
| export * from './flag'; | ||
| export * from './follow'; | ||
| export * from './like'; | ||
| export * from './logout'; | ||
| export * from './mod'; | ||
| export * from './post'; | ||
| export * from './postRemove'; | ||
| export * from './registerHandle'; | ||
| export * from './reply'; | ||
| export * from './transferHandle'; | ||
| export * from './unfollow'; | ||
| export * from './updateState'; |
Oops, something went wrong.
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.
We'll also need to store the profile picture (and possibly other new fields in the future, see #491), so I was thinking we could create an account/profile table instead of one specifically for the handle. Wdyt?
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.
@luciorubeens
handletable was renamed toaccountin 9447752Protocol related code was refactored to work with the new table in bf956b9
Changes added more complexity to the code but I guess it will make it easier for the new user related features to be implemented.