-
Notifications
You must be signed in to change notification settings - Fork 21
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
Refactor Abstraxion to fetch config #121
Changes from 10 commits
68136d1
12b995f
a0526fc
536ed94
7425cec
223972b
95f6400
61b7241
285ab35
4e55e98
2ab0bac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@burnt-labs/abstraxion": minor | ||
"@burnt-labs/constants": minor | ||
--- | ||
|
||
Refactor Abstraxion to fetch config |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,3 +1,5 @@ | ||||||
import { RpcStatusResponse } from "./types"; | ||||||
|
||||||
export interface Coin { | ||||||
coinDenom: string; | ||||||
coinMinimalDenom: string; | ||||||
|
@@ -22,11 +24,6 @@ interface Bip44 { | |||||
coinType: number; | ||||||
} | ||||||
|
||||||
interface Gas { | ||||||
price: string; | ||||||
denom: string; | ||||||
} | ||||||
|
||||||
export interface ChainInfo { | ||||||
rpc: string; | ||||||
rest: string; | ||||||
|
@@ -88,3 +85,26 @@ export const testChainInfo: ChainInfo = { | |||||
chainId: "xion-local-testnet-1", | ||||||
chainName: "Xion Testnet Local", | ||||||
}; | ||||||
|
||||||
// If mainnet chain-id/network changes be sure to update here. | ||||||
const DASHBOARD_URLS = { | ||||||
"xion-mainnet-1": "dashboard.burnt.com", | ||||||
"xion-testnet-1": "testnet-dashboard.burnt.com", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can make this change but I was under the impression that we wanted to stay away from using too many "." and thus the reason for the hyphenated sub-domain |
||||||
}; | ||||||
|
||||||
export async function fetchConfig(rpcUrl: string): Promise<string> { | ||||||
try { | ||||||
const fetchReq = await fetch(`${rpcUrl}/status`); | ||||||
if (!fetchReq.ok) { | ||||||
throw new Error("Something went wrong querying RPC"); | ||||||
} | ||||||
|
||||||
const data: RpcStatusResponse = await fetchReq.json(); | ||||||
const lookup = data.result.node_info.network; | ||||||
const returnUrl = DASHBOARD_URLS[lookup as keyof typeof DASHBOARD_URLS]; | ||||||
if (!returnUrl) throw new Error("Network not found."); | ||||||
return returnUrl; | ||||||
} catch (error) { | ||||||
throw error; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Interface for rpc status response | ||
export interface RpcStatusResponse { | ||
jsonrpc: string; | ||
id: number; | ||
result: RpcStatusResult; | ||
} | ||
|
||
export interface RpcStatusResult { | ||
node_info: RpcStatusResultNodeInfo; | ||
sync_info: RpcStatusResultSyncInfo; | ||
} | ||
|
||
export interface RpcStatusResultNodeInfo { | ||
protocol_version: any; | ||
id: string; | ||
network: string; | ||
version: string; | ||
channels: string; | ||
moniker: string; | ||
other: any; | ||
} | ||
|
||
export interface RpcStatusResultSyncInfo { | ||
latest_block_hash: string; | ||
latest_app_hash: string; | ||
latest_block_height: string; | ||
latest_block_time: string; | ||
earliest_block_hash: string; | ||
earliest_app_hash: string; | ||
earliest_block_height: string; | ||
earliest_block_time: string; | ||
catching_up: boolean; | ||
} |
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.
The dashboard URL might be local, should include the protocol in the passed var