Skip to content

Commit

Permalink
fix: issue with crypto provider default fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
juanky201271 committed Nov 9, 2024
1 parent 46311c1 commit e154f62
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ crate-type = ["cdylib"]
zingolib = { git="https://github.com/zingolabs/zingolib", default-features=true, tag = "1.8.1", features=["test-elevation"] }
http = "1.1.0"
lazy_static = "1.4.0"
tokio = { version = "1.28.2", features = [ "full" ] }
tokio = { version = "1.24", features = ["full"] }
rustls = { version = "0.23.13", features = ["ring"] }

[dependencies.neon]
version = "1"
Expand Down
26 changes: 25 additions & 1 deletion native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ extern crate lazy_static;
use neon::prelude::*;

use tokio::runtime::Runtime;

use rustls::crypto::ring::default_provider;
use rustls::crypto::CryptoProvider;

use std::thread;

use std::cell::RefCell;
Expand Down Expand Up @@ -38,6 +42,7 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
cx.export_function("zingolib_get_latest_block_server", zingolib_get_latest_block_server)?;
cx.export_function("zingolib_get_transaction_summaries", zingolib_get_transaction_summaries)?;
cx.export_function("zingolib_get_value_transfers", zingolib_get_value_transfers)?;
cx.export_function("zingolib_set_crypto_default_provider_to_ring", zingolib_set_crypto_default_provider_to_ring)?;

Ok(())
}
Expand Down Expand Up @@ -331,4 +336,23 @@ fn zingolib_get_value_transfers(mut cx: FunctionContext) -> JsResult<JsString> {
};

Ok(cx.string(resp))
}
}

pub fn zingolib_set_crypto_default_provider_to_ring(mut cx: FunctionContext) -> JsResult<JsString> {
let resp: String;
{
if CryptoProvider::get_default().is_none() {
resp = match default_provider()
.install_default()
.map_err(|_| "Error: Failed to install crypto provider".to_string())
{
Ok(_) => "true".to_string(),
Err(e) => e,
};
} else {
resp = "true".to_string();
};
}

Ok(cx.string(resp))
}
4 changes: 4 additions & 0 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ function createWindow() {
return await settings.set(`all.${kv.key}`, kv.value);
});

ipcMain.handle('get-app-data-path', () => {
return app.getPath('appData');
});

ipcMain.on("apprestart", () => {
app.relaunch({ args: process.argv.slice(1).concat(['--relaunch']) })
app.exit(0)
Expand Down
5 changes: 3 additions & 2 deletions src/components/addressbook/AddressbookImpl.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import path from "path";
import { AddressBookEntry } from "../appstate";

const { remote } = window.require("electron");
const { ipcRenderer } = window.require("electron");
const fs = window.require("fs");

// Utility class to save / read the address book.
export default class AddressbookImpl {
static async getFileName(): Promise<string> {
const dir: string = path.join(remote.app.getPath("appData"), "Zingo PC");
const relativePath: string = await ipcRenderer.invoke('get-app-data-path');
const dir: string = path.join(relativePath, 'Zingo PC');
if (!fs.existsSync(dir)) {
await fs.promises.mkdir(dir);
}
Expand Down
3 changes: 3 additions & 0 deletions src/components/loadingscreen/LoadingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class LoadingScreen extends Component<LoadingScreenProps & RouteComponentProps,
})
console.log('did mount, disable TRUE');

const r = native.zingolib_set_crypto_default_provider_to_ring();
console.log('crypto provider result', r);

const { rescanning, prevSyncId } = this.context;
if (rescanning) {
await this.runSyncStatusPoller(prevSyncId);
Expand Down
1 change: 1 addition & 0 deletions src/native.node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export function zingolib_execute_spawn(cmd: string, args: string): string;
export function zingolib_execute_async(cmd: string, args: string): Promise<string>;
export function zingolib_get_transaction_summaries(): string;
export function zingolib_get_value_transfers(): string;
export function zingolib_set_crypto_default_provider_to_ring(): string;
2 changes: 1 addition & 1 deletion src/rpc/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export default class RPC {
info.testnet = infoJSON.chain_name === "test";
info.latestBlock = infoJSON.latest_block_height;
info.connections = 1;
info.version = `${infoJSON.vendor}/${infoJSON.git_commit.substring(0, 6)}/${infoJSON.version}`;
info.version = `${infoJSON.vendor}/${infoJSON.git_commit ? infoJSON.git_commit.substring(0, 6) : ""}/${infoJSON.version}`;
info.zcashdVersion = "Not Available";
info.currencyName = info.testnet ? "TAZ" : "ZEC";
info.solps = 0;
Expand Down

0 comments on commit e154f62

Please sign in to comment.