-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: #163: pair selector #204
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2e19515
fix: apply new UI changes of density
VanishMax 3ff27f5
feat: set up new PairSelector
VanishMax 95371ee
feat: add star-pair feature
VanishMax 3c81cfc
feat: implement basic pair selection
VanishMax ee230a2
Merge branch 'main' into feat/#163-asset-selector
VanishMax 70668e4
refactor: create more components related to pair selector
VanishMax 11e69eb
feat: implement filtering input
VanishMax 70fc5c2
feat: implement `/api/pairs` endpoint to fetch the most popular pairs
VanishMax 0ac5e99
feat: implement recent assets in search results
VanishMax c5fe6b2
feat: use balances in the search results
VanishMax 0347176
fix: small bugs
VanishMax a0f7496
Merge branch 'main' into feat/#163-asset-selector
VanishMax 9935846
fix: merge
VanishMax b24d374
fix: ts
VanishMax a87bee6
fix: handle the pr feedback
VanishMax 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { GET } from '@/shared/api/server/summary/pairs'; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 @@ | ||
export { StarButton } from './star-button'; | ||
export { starStore } from './store'; | ||
export type { Pair } from './storage'; |
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,40 @@ | ||
import { FC, MouseEventHandler } from 'react'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { Star } from 'lucide-react'; | ||
import { Button } from '@penumbra-zone/ui/Button'; | ||
import { Density } from '@penumbra-zone/ui/Density'; | ||
import StarFilled from './star-filled.svg'; | ||
import type { Pair } from './storage'; | ||
import { starStore } from './store'; | ||
|
||
export interface StarButtonProps { | ||
pair: Pair; | ||
adornment?: boolean; | ||
} | ||
|
||
export const StarButton = observer(({ pair, adornment }: StarButtonProps) => { | ||
const { star, unstar, isStarred } = starStore; | ||
const starred = isStarred(pair); | ||
|
||
const onClick: MouseEventHandler<HTMLButtonElement> = event => { | ||
event.stopPropagation(); | ||
if (starred) { | ||
unstar(pair); | ||
} else { | ||
star(pair); | ||
} | ||
}; | ||
|
||
return ( | ||
<Density compact> | ||
<Button | ||
icon={starred ? (StarFilled as FC) : Star} | ||
priority={adornment ? 'primary' : 'secondary'} | ||
iconOnly={adornment ? 'adornment' : true} | ||
onClick={onClick} | ||
> | ||
Favorite | ||
</Button> | ||
</Density> | ||
); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,35 @@ | ||
import { Metadata } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb'; | ||
|
||
export interface Pair { | ||
base: Metadata; | ||
quote: Metadata; | ||
} | ||
|
||
const STAR_STORE_LS_KEY = 'star-pairs-store'; | ||
|
||
export const getStarredPairs = (): Pair[] => { | ||
try { | ||
const data = JSON.parse(localStorage.getItem(STAR_STORE_LS_KEY) ?? '[]') as { | ||
base: string; | ||
quote: string; | ||
}[]; | ||
return data.map(pair => ({ | ||
base: Metadata.fromJson(pair.base), | ||
quote: Metadata.fromJson(pair.quote), | ||
})); | ||
} catch (_) { | ||
return []; | ||
} | ||
}; | ||
|
||
export const setStarredPairs = (pairs: Pair[]): void => { | ||
localStorage.setItem( | ||
STAR_STORE_LS_KEY, | ||
JSON.stringify( | ||
pairs.map(pair => ({ | ||
base: pair.base.toJson(), | ||
quote: pair.quote.toJson(), | ||
})), | ||
), | ||
); | ||
}; |
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,34 @@ | ||
import { makeAutoObservable } from 'mobx'; | ||
import { Pair, getStarredPairs, setStarredPairs } from './storage'; | ||
|
||
class StarStateStore { | ||
pairs: Pair[] = []; | ||
|
||
constructor() { | ||
makeAutoObservable(this); | ||
} | ||
|
||
star = (pair: Pair) => { | ||
this.pairs = [...this.pairs, pair]; | ||
setStarredPairs(this.pairs); | ||
}; | ||
|
||
unstar = (pair: Pair) => { | ||
this.pairs = this.pairs.filter( | ||
value => !value.base.equals(pair.base) || !value.quote.equals(pair.quote), | ||
); | ||
setStarredPairs(this.pairs); | ||
}; | ||
|
||
setup() { | ||
this.pairs = getStarredPairs(); | ||
} | ||
|
||
isStarred = (pair: Pair): boolean => { | ||
return this.pairs.some( | ||
value => value.base.symbol === pair.base.symbol && value.quote.symbol === pair.quote.symbol, | ||
); | ||
}; | ||
} | ||
|
||
export const starStore = new StarStateStore(); |
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,13 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import type { PairData } from '@/shared/api/server/summary/pairs'; | ||
import { apiFetch } from '@/shared/utils/api-fetch'; | ||
|
||
// Fetches the array of popular (sorted by liquidity) pairs | ||
export const usePairs = () => { | ||
return useQuery({ | ||
queryKey: ['pairs'], | ||
queryFn: async () => { | ||
return apiFetch<PairData[]>('/api/pairs'); | ||
}, | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
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.
question: would it be easier if we just stored symbol pairs versus the whole metadata objects?
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.
this would delay showing data to user. Idk, for me it's more complicated to calculate the Metadata from symbol than storing it like this