-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: apply new UI changes of density * feat: set up new PairSelector * feat: add star-pair feature * feat: implement basic pair selection * refactor: create more components related to pair selector * feat: implement filtering input * feat: implement `/api/pairs` endpoint to fetch the most popular pairs * feat: implement recent assets in search results * feat: use balances in the search results * fix: small bugs * fix: merge * fix: ts * fix: handle the pr feedback
- Loading branch information
Showing
26 changed files
with
1,005 additions
and
136 deletions.
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.