-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from rainlanguage/2024-01-23-gui-chainid
2024 01 23 gui chainid
- Loading branch information
Showing
13 changed files
with
114 additions
and
17 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
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
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,16 @@ | ||
use alloy_ethers_typecast::transaction::ReadableClientHttp; | ||
|
||
#[tauri::command] | ||
pub async fn get_chainid(rpc_url: String) -> Result<u64, String> { | ||
let chain_id = ReadableClientHttp::new_from_url(rpc_url) | ||
.map_err(|_| String::from("Failed to connect to RPC URL"))? | ||
.get_chainid() | ||
.await | ||
.map_err(|_| String::from("Failed to get Chain ID"))?; | ||
|
||
let chain_id_u64: u64 = chain_id | ||
.try_into() | ||
.map_err(|_| String::from("Failed to convert Chain ID to u64"))?; | ||
|
||
Ok(chain_id_u64) | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod chain; | ||
pub mod vault; | ||
pub mod wallet; |
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,29 @@ | ||
import find from 'lodash/find'; | ||
import { derived, writable, get } from 'svelte/store'; | ||
import * as chains from 'viem/chains' | ||
import { rpcUrl } from './settings'; | ||
import { toasts } from './toasts'; | ||
import { ToastMessageType } from '$lib/typeshare/toast'; | ||
import { invoke } from '@tauri-apps/api'; | ||
|
||
export const chainId = writable(parseInt(localStorage.getItem("settings.chainId") || '1')) | ||
|
||
chainId.subscribe(value => { | ||
localStorage.setItem("settings.chainId", (value || 0).toString()); | ||
}); | ||
|
||
export async function updateChainId() { | ||
try { | ||
const val: number = await invoke('get_chainid', {rpcUrl: get(rpcUrl)}); | ||
chainId.set(val); | ||
} catch(e) { | ||
toasts.add({ | ||
message_type: ToastMessageType.Error, | ||
text: e as string | ||
}); | ||
} | ||
} | ||
|
||
export const activeChain = derived(chainId, (val) => { | ||
return find(Object.values(chains), (c) => c.id === val); | ||
}) |
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