-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- release-2024.14
- release-2024.13
- release-2024.12
- release-2024.11
- release-2024.10
- release-2024.9
- release-2024.8
- release-2024.7
- release-2024.6
- release-2024.5
- release-2024.4
- release-2024.3
- release-2024.2
- release-2024.1
- release-2023.15
- release-2023.14
- release-2023.13
- release-2023.12
- release-2023.11
- release-2023.10
- release-2023.9
- release-2023.8
- release-2023.7
Showing
15 changed files
with
2,683 additions
and
2,029 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,18 @@ | ||
name: Branches | ||
on: | ||
push: | ||
branches: [main] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
sync-main-dev: | ||
name: branch main -> dev | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Fast-forward main -> dev | ||
run: | | ||
git checkout dev | ||
git merge --ff-only main | ||
git push --set-upstream origin dev |
Submodule chain-registry
updated
124 files
Large diffs are not rendered by default.
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
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,91 @@ | ||
import { createContext, ReactNode, useContext, useEffect, useRef } from "react"; | ||
import { create } from "zustand"; | ||
|
||
import { Args, useUsdDiffValue, useUsdValue } from "@/hooks/useUsdValue"; | ||
|
||
type UsdValueProps = Args & { | ||
loading?: ReactNode; | ||
context?: "src" | "dest"; | ||
}; | ||
|
||
export const UsdValue = ({ | ||
loading = "...", | ||
context, | ||
...args | ||
}: UsdValueProps) => { | ||
const { data: usdValue = 0, isLoading } = useUsdValue(args); | ||
|
||
const contextStore = useContext(ctx); | ||
useEffect(() => { | ||
if (contextStore && context) { | ||
contextStore.setState({ [context]: args }); | ||
return () => { | ||
contextStore.setState({ [context]: undefined }); | ||
}; | ||
} | ||
}); | ||
|
||
return <>{isLoading ? loading : `$${usdValue.toFixed(2)}`}</>; | ||
}; | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
type Store = { src?: Args; dest?: Args }; | ||
|
||
const createContextStore = () => { | ||
return create<Store>(() => ({ src: undefined, dest: undefined })); | ||
}; | ||
|
||
type Context = ReturnType<typeof createContextStore> | undefined; | ||
const ctx = createContext<Context>(undefined); | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
type UsdDiffValueProps = { | ||
src: Args; | ||
dest: Args; | ||
onLoading?: ReactNode; | ||
onUndefined?: ReactNode; | ||
children?: (args: { isLoading: boolean; percentage: number }) => ReactNode; | ||
}; | ||
|
||
export const UsdDiffValue = (props: UsdDiffValueProps) => { | ||
const { src, dest, onLoading = "...", children } = props; | ||
const { data: percentage = 0, isLoading } = useUsdDiffValue([src, dest]); | ||
|
||
if (children) { | ||
return <>{children({ isLoading, percentage })}</>; | ||
} | ||
if (isLoading) { | ||
return <>{onLoading}</>; | ||
} | ||
return <>{percentage.toFixed(2)}%</>; | ||
}; | ||
|
||
export const UsdDiff = { | ||
Provider: ({ children }: { children: ReactNode }) => { | ||
const store = useRef<Context>(createContextStore()); | ||
return <ctx.Provider value={store.current}>{children}</ctx.Provider>; | ||
}, | ||
Value: (props: Omit<UsdDiffValueProps, "src" | "dest">) => { | ||
const useStore = useContext(ctx); | ||
if (!useStore) { | ||
throw new Error("UsdDiff.Value must be used inside UsdDiff.Provider"); | ||
} | ||
|
||
const { src, dest } = useStore(); | ||
if (!(src && dest)) { | ||
return <>{props.onUndefined ?? null}</>; | ||
} | ||
|
||
return <UsdDiffValue src={src} dest={dest} {...props} />; | ||
}, | ||
}; | ||
|
||
export const useUsdDiffReset = () => { | ||
const store = useContext(ctx); | ||
if (!store) { | ||
throw new Error("useUsdDiffReset must be used inside UsdDiff.Provider"); | ||
} | ||
return () => store.setState({ src: undefined, dest: undefined }); | ||
}; |
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,77 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useMemo } from "react"; | ||
|
||
import { getAssets } from "@/chains"; | ||
import { raise } from "@/utils/assert"; | ||
import { getUsdPrice } from "@/utils/llama"; | ||
|
||
export interface Args { | ||
chainId: string; | ||
denom: string; | ||
value: string; | ||
} | ||
|
||
export function useUsdValue({ chainId, denom, value }: Args) { | ||
const queryKey = useMemo( | ||
() => ["USE_USD_VALUE", chainId, denom, value] as const, | ||
[chainId, denom, value], | ||
); | ||
|
||
const enabled = useMemo(() => { | ||
const parsed = parseFloat(value); | ||
return !isNaN(parsed) && parsed > 0; | ||
}, [value]); | ||
|
||
return useQuery({ | ||
queryKey, | ||
queryFn: async ({ queryKey: [, chainId, denom, value] }) => { | ||
return getUsdValue({ chainId, denom, value }); | ||
}, | ||
staleTime: 1000 * 60, // 1 minute | ||
enabled, | ||
}); | ||
} | ||
|
||
export function useUsdDiffValue([args1, args2]: [Args, Args]) { | ||
const queryKey = useMemo(() => { | ||
const hash = [...Object.values(args1), ...Object.values(args2)].join("-"); | ||
return ["USE_USD_DIFF_VALUES", hash] as const; | ||
}, [args1, args2]); | ||
|
||
const enabled = useMemo(() => { | ||
const parsed1 = parseFloat(args1.value); | ||
const parsed2 = parseFloat(args2.value); | ||
return !isNaN(parsed1) && parsed1 > 0 && !isNaN(parsed2) && parsed2 > 0; | ||
}, [args1.value, args2.value]); | ||
|
||
return useQuery({ | ||
// intentionally not including args1 and args2 since query key is using | ||
// hashed values of args1 and args2 | ||
// eslint-disable-next-line @tanstack/query/exhaustive-deps | ||
queryKey, | ||
queryFn: async () => { | ||
const [v1, v2] = await Promise.all([ | ||
getUsdValue(args1), | ||
getUsdValue(args2), | ||
]); | ||
// return percentage difference | ||
return ((v2 - v1) / v1) * 100; | ||
}, | ||
staleTime: 1000 * 60, // 1 minute | ||
enabled, | ||
}); | ||
} | ||
|
||
async function getUsdValue({ chainId, denom, value }: Args) { | ||
const assets = getAssets(chainId); | ||
const asset = | ||
assets.find((asset) => asset.base === denom) || | ||
raise(`getUsdValue error: ${denom} not found in ${chainId}`); | ||
const coingeckoId = | ||
asset.coingecko_id || | ||
raise( | ||
`getUsdValue error: ${denom} does not have a 'coingecko_id' in ${chainId}`, | ||
); | ||
const usd = await getUsdPrice({ coingeckoId }); | ||
return parseFloat(value) * usd; | ||
} |
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,34 @@ | ||
import { z } from "zod"; | ||
|
||
interface Args { | ||
coingeckoId: string; | ||
} | ||
|
||
const cache = new Map<string, number>(); | ||
|
||
export async function getUsdPrice({ coingeckoId }: Args) { | ||
const cached = cache.get(coingeckoId); | ||
if (cached) return cached; | ||
|
||
const endpoint = `https://coins.llama.fi/prices/current/coingecko:${coingeckoId}`; | ||
|
||
const response = await fetch(endpoint); | ||
const data = await response.json(); | ||
|
||
const { coins } = await priceResponseSchema.parseAsync(data); | ||
const { price } = coins[`coingecko:${coingeckoId}`]; | ||
|
||
cache.set(coingeckoId, price); | ||
return price; | ||
} | ||
|
||
const priceResponseSchema = z.object({ | ||
coins: z.record( | ||
z.object({ | ||
price: z.number(), | ||
symbol: z.string(), | ||
timestamp: z.number(), | ||
confidence: z.number(), | ||
}), | ||
), | ||
}); |
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,26 @@ | ||
import { InjectedConnector } from "@wagmi/core"; | ||
|
||
export const OKXConnector = new InjectedConnector({ | ||
options: { | ||
name: "OKX Wallet", | ||
shimDisconnect: true, | ||
getProvider: () => { | ||
if (typeof window === 'undefined') return | ||
|
||
if (typeof window.okexchain === 'undefined') return | ||
|
||
if (typeof window.ethereum !== 'undefined') return window.ethereum | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const isOkxWallet = (ethereum?: any) => !!ethereum?.isOkxWallet | ||
|
||
if (isOkxWallet(window.okexchain.ethereum)) return window.okexchain.ethereum | ||
|
||
if (window.okexchain.ethereum?.providers) { | ||
return window.okexchain.ethereum.providers.find(isOkxWallet) | ||
} | ||
|
||
return window["okexchain"]["ethereum"] ?? null | ||
} | ||
} | ||
}) |
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
a22908f
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.
Successfully deployed to the following URLs:
ibc-dot-fun – ./
ibc-dot-fun.vercel.app
ibc-dot-fun-skip-protocol.vercel.app
ibc.fun
ibc-dot-fun-git-main-skip-protocol.vercel.app
www.ibc.fun