From 1a0c6eed275a2530407301ac9964e7435ef34847 Mon Sep 17 00:00:00 2001 From: fmtabbara Date: Thu, 14 Oct 2021 16:30:09 +0100 Subject: [PATCH] Tauri wallet --- tauri-wallet/Cargo.lock | 153 ++++++++++-------- tauri-wallet/README.md | 38 +++-- tauri-wallet/package.json | 5 +- tauri-wallet/src-tauri/src/main.rs | 4 +- .../src-tauri/src/operations/account.rs | 10 +- .../src-tauri/src/operations/delegate.rs | 25 +++ tauri-wallet/src/components/Nav.tsx | 24 +-- tauri-wallet/src/requests/index.ts | 7 + .../src/routes/delegate/DelegateForm.tsx | 2 +- tauri-wallet/src/routes/delegate/index.tsx | 5 +- .../src/routes/internal-docs/index.tsx | 6 +- tauri-wallet/src/routes/sign-in.tsx | 3 +- .../src/routes/undelegate/UndelegateForm.tsx | 68 +++++--- tauri-wallet/src/routes/undelegate/index.tsx | 110 +++++++++---- tauri-wallet/src/types/global.ts | 6 + tauri-wallet/src/types/rust/account.ts | 2 +- tauri-wallet/src/types/rust/stateparams.ts | 1 - 17 files changed, 307 insertions(+), 162 deletions(-) diff --git a/tauri-wallet/Cargo.lock b/tauri-wallet/Cargo.lock index cec8fe76d8..f1235d5abd 100644 --- a/tauri-wallet/Cargo.lock +++ b/tauri-wallet/Cargo.lock @@ -53,9 +53,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.44" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1" +checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf" [[package]] name = "arrayref" @@ -302,18 +302,18 @@ dependencies = [ [[package]] name = "bstr" -version = "0.2.17" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +checksum = "90682c8d613ad3373e66de8c6411e0ae2ab2571e879d2efbf73558cc66f21279" dependencies = [ "memchr", ] [[package]] name = "bumpalo" -version = "3.7.1" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" +checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631" [[package]] name = "byte-tools" @@ -356,9 +356,9 @@ dependencies = [ [[package]] name = "cairo-rs" -version = "0.14.7" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9164355c892b026d6257e696dde5f3cb39beb3718297f0f161b562fe2ee3ab86" +checksum = "f859ade407c19810ae920b4fafab92189ed312adad490d08fb16b5f49f1e2207" dependencies = [ "bitflags", "cairo-sys-rs", @@ -551,9 +551,9 @@ dependencies = [ [[package]] name = "const-oid" -version = "0.6.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdab415d6744056100f40250a66bc430c1a46f7a02e20bc11c94c79a0f0464df" +checksum = "44c32f031ea41b4291d695026c023b95d59db2d8a2c7640800ed56bc8f510f22" [[package]] name = "constant_time_eq" @@ -796,9 +796,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto-bigint" -version = "0.2.10" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d12477e115c0d570c12a2dfd859f80b55b60ddb5075df210d3af06d133a69f45" +checksum = "e49339137316df1914fdb54a5eae75a73f45068fd0d2178fe235b11d93238a6e" dependencies = [ "generic-array 0.14.4", "rand_core 0.6.3", @@ -922,9 +922,9 @@ dependencies = [ [[package]] name = "der" -version = "0.4.3" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2adca118c71ecd9ae094d4b68257b3fdfcb711a612b9eec7b5a0d27a5a70a5b4" +checksum = "31e21d2d0f22cde6e88694108429775c0219760a07779bf96503b434a03d7412" dependencies = [ "const-oid", ] @@ -1237,9 +1237,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.22" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" +checksum = "80edafed416a46fb378521624fab1cfa2eb514784fd8921adbe8a8d8321da811" dependencies = [ "cfg-if 1.0.0", "crc32fast", @@ -1558,9 +1558,9 @@ checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7" [[package]] name = "gio" -version = "0.14.6" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a29d8062af72045518271a2cd98b4e1617ce43f5b4223ad0fb9a0eff8f718c" +checksum = "81a4c12fcba7a6402ae843a0085ec16d3658a87901763b6a7f0a7c5d60e555a5" dependencies = [ "bitflags", "futures-channel", @@ -1626,7 +1626,7 @@ checksum = "2aad66361f66796bfc73f530c51ef123970eb895ffba991a234fcf7bea89e518" dependencies = [ "anyhow", "heck", - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.0.0", "proc-macro-error", "proc-macro2", "quote", @@ -1749,7 +1749,7 @@ checksum = "21de1da96dc117443fb03c2e270b2d34b7de98d0a79a19bbb689476173745b79" dependencies = [ "anyhow", "heck", - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.0.0", "proc-macro-error", "proc-macro2", "quote", @@ -1884,9 +1884,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.5" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" +checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" dependencies = [ "bytes", "fnv", @@ -1940,9 +1940,9 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.13" +version = "0.14.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15d1cfb9e4f68655fa04c01f59edb405b6074a0f7118ea881e5026e4a1cd8593" +checksum = "13f67199e765030fa08fe0bd581af683f0d5bc04ea09c2b1102012c5fb90e7fd" dependencies = [ "bytes", "futures-channel", @@ -2091,9 +2091,9 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.11" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd" +checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d" dependencies = [ "cfg-if 1.0.0", ] @@ -2223,9 +2223,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.102" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" +checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" [[package]] name = "lock_api" @@ -2551,7 +2551,7 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "486ea01961c4a818096de679a8b740b26d9033146ac5291b1c98557658f8cdd9" dependencies = [ - "proc-macro-crate 1.1.0", + "proc-macro-crate 1.0.0", "proc-macro2", "quote", "syn", @@ -2660,9 +2660,9 @@ checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" [[package]] name = "openssl-sys" -version = "0.9.67" +version = "0.9.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69df2d8dfc6ce3aaf44b40dec6f487d5a886516cf6879c49e98e0710f310a058" +checksum = "1996d2d305e561b70d1ee0c53f1542833f4e1ac6ce9a6708b6ff2738ca67dc82" dependencies = [ "autocfg 1.0.1", "cc", @@ -2935,9 +2935,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkcs8" -version = "0.7.6" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee3ef9b64d26bad0536099c816c6734379e45bbd5f14798def6809e5cc350447" +checksum = "fbee84ed13e44dd82689fa18348a49934fa79cc774a344c42fc9b301c71b140a" dependencies = [ "der", "spki", @@ -2945,9 +2945,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.20" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c9b1041b4387893b91ee6746cddfc28516aff326a3519fb2adf820932c5e6cb" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "pmutil" @@ -3007,9 +3007,9 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.1.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" +checksum = "41fdbd1df62156fbc5945f4762632564d7d038153091c3fcf1067f6aef7cff92" dependencies = [ "thiserror", "toml", @@ -3550,9 +3550,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.6" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7a48d098c2a7fdf5740b19deb1181b4fb8a9e68e03ae517c14cde04b5725409" +checksum = "bc6ab463ae35acccb5cba66c0084c985257b797d288b6050cc2f6ac1b266cb78" dependencies = [ "dyn-clone", "schemars_derive", @@ -3562,9 +3562,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.6" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a9ea2a613fe4cd7118b2bb101a25d8ae6192e1975179b67b2f17afd11e70ac8" +checksum = "902fdfbcf871ae8f653bddf4b2c05905ddaabc08f69d32a915787e3be0d31356" dependencies = [ "proc-macro2", "quote", @@ -3712,9 +3712,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.68" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" +checksum = "a7f9e390c27c3c0ce8bc5d725f6e4d30a29d26659494aa4b17535f7522c5c950" dependencies = [ "itoa", "ryu", @@ -3855,9 +3855,9 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "socket2" -version = "0.4.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" +checksum = "765f090f0e423d2b55843402a07915add955e7d60657db13707a159727326cad" dependencies = [ "libc", "winapi", @@ -3886,9 +3886,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "spki" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c01a0c15da1b0b0e1494112e7af814a678fec9bd157881b49beac661e9b6f32" +checksum = "987637c5ae6b3121aba9d513f869bd2bff11c4cc086c22473befd6649c0bd521" dependencies = [ "der", ] @@ -4501,6 +4501,15 @@ dependencies = [ "utf-8", ] +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + [[package]] name = "thin-slice" version = "0.1.1" @@ -4564,9 +4573,9 @@ checksum = "25eb0ca3468fc0acc11828786797f6ef9aa1555e4a211a60d64cc8e4d1be47d6" [[package]] name = "tokio" -version = "1.12.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" +checksum = "b4efe6fc2395938c8155973d7be49fe8d03a843726e285e100a8a383cc0154ce" dependencies = [ "autocfg 1.0.1", "bytes", @@ -4642,9 +4651,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" -version = "0.1.28" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8" +checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ "cfg-if 1.0.0", "pin-project-lite", @@ -4654,9 +4663,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.16" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98863d0dd09fa59a1b79c6750ad80dbda6b75f4e71c437a6a1a8cb91a8bcbd77" +checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" dependencies = [ "proc-macro2", "quote", @@ -4665,9 +4674,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.20" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46125608c26121c81b0c6d693eab5a420e416da7e43c426d2e8f7df8da8a3acf" +checksum = "2ca517f43f0fb96e0c3072ed5c275fe5eece87e8cb52f4a77b69226d3b1c9df8" dependencies = [ "lazy_static", ] @@ -4680,9 +4689,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "ts-rs" -version = "3.1.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "369e48de67506679b3a576b0faf666fa9f9acf2fd00b4c61e28bdb6c8e08ec06" +checksum = "89634b937615f3e50462b9529a36aa309d557c893eb79ce8a93d7e1915820859" dependencies = [ "dprint-plugin-typescript", "ts-rs-macros", @@ -4690,14 +4699,15 @@ dependencies = [ [[package]] name = "ts-rs-macros" -version = "3.1.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f269e8fd28e26b4cdbd01f81f345aaf666131511e54a735a76a614b5062d0a5a" +checksum = "117c837b4f78dbaa8e7d06aefae35267f49cb0a47f5df4ed75b777acb83ba14d" dependencies = [ "Inflector", "proc-macro2", "quote", "syn", + "termcolor", ] [[package]] @@ -4747,9 +4757,9 @@ checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" [[package]] name = "unicode-xid" @@ -5016,9 +5026,9 @@ dependencies = [ [[package]] name = "webview2" -version = "0.1.3" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b132bb76313456e93b17037262a030d54c9fe0f11838ef1593f845e3807ef8a" +checksum = "6fab1ccfdabb098b047293c8d496c1914d1c654b68fdaa3bb77cfa47c4bca2c7" dependencies = [ "com", "once_cell", @@ -5029,9 +5039,9 @@ dependencies = [ [[package]] name = "webview2-sys" -version = "0.1.1" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24b7889e893ac4c50d7346356be3ce13a85e56512c38b8fde0526559b8012a4c" +checksum = "cc5288cef1e0cbcf7a0b961e6271e33589b8989c80b2e11078504e989b5346ff" dependencies = [ "com", "winapi", @@ -5130,12 +5140,13 @@ dependencies = [ [[package]] name = "x11-dl" -version = "2.19.1" +version = "2.18.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea26926b4ce81a6f5d9d0f3a0bc401e5a37c6ae14a1bfaa8ff6099ca80038c59" +checksum = "2bf981e3a5b3301209754218f962052d4d9ee97e478f4d26d4a6eced34c1fef8" dependencies = [ "lazy_static", "libc", + "maybe-uninit", "pkg-config", ] @@ -5150,18 +5161,18 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.4.2" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf68b08513768deaa790264a7fac27a58cbf2705cfcdc9448362229217d7e970" +checksum = "377db0846015f7ae377174787dd452e1c5f5a9050bc6f954911d01f116daa0cd" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.2.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdff2024a851a322b08f179173ae2ba620445aef1e838f0c196820eade4ae0c7" +checksum = "a2c1e130bebaeab2f23886bf9acbaca14b092408c452543c857f66399cd6dab1" dependencies = [ "proc-macro2", "quote", diff --git a/tauri-wallet/README.md b/tauri-wallet/README.md index db954805b7..465cd18132 100644 --- a/tauri-wallet/README.md +++ b/tauri-wallet/README.md @@ -3,17 +3,37 @@ Copyright 2020 - Nym Technologies SA SPDX-License-Identifier: Apache-2.0 --> -# Nym Tauri Wallet +# Nym Tauri Wallet -A Rust and Tauri desktop wallet implementation. +A Rust and Tauri desktop wallet implementation. -## Installation prerequisites +## Installation prerequisites -* `Yarn` -* `NodeJS >= v16.8.0` -* `Rust & cargo >= v1.51` +- `Yarn` +- `NodeJS >= v16.8.0` +- `Rust & cargo >= v1.51` -## Installation & usage +## Installation -* `yarn install` -* `yarn dev` +Inside of the `tauri-wallet` folder, run the following commands + +- `yarn install` + +## Development mode + +You can run the wallet without having to install it in development mode by running the following terminal command from the `tauri-wallet` folder + +`yarn dev` + +## Production mode + +To build and install the wallet, run the following terminal command from the `tauri-wallet` folder + +`$ yarn build` + +This will build an executable file that you can use to install the wallet on your machine + +## Install the wallet + +Once the the building process is complete an installation file can be found in the following location `tauri-wallet/target/release/nym_wallet` +`` diff --git a/tauri-wallet/package.json b/tauri-wallet/package.json index 0c8c172fa3..a628f5470a 100644 --- a/tauri-wallet/package.json +++ b/tauri-wallet/package.json @@ -5,8 +5,11 @@ "license": "MIT", "scripts": { "webpack:dev": "yarn webpack serve", + "webpack:build": "yarn webpack", "tauri:dev": "yarn tauri dev", - "dev": "yarn run webpack:dev & yarn run tauri:dev " + "tauri:build": "yarn tauri build", + "dev": "yarn run webpack:dev & yarn run tauri:dev", + "build": "yarn run webpack:build & yarn run tauri:build" }, "dependencies": { "@babel/preset-typescript": "^7.15.0", diff --git a/tauri-wallet/src-tauri/src/main.rs b/tauri-wallet/src-tauri/src/main.rs index 1b6a7c3ebd..28aecff021 100644 --- a/tauri-wallet/src-tauri/src/main.rs +++ b/tauri-wallet/src-tauri/src/main.rs @@ -57,7 +57,9 @@ fn main() { create_new_account, get_fee, get_state_params, - update_state_params + update_state_params, + get_reverse_mix_delegations_paged, + get_reverse_gateway_delegations_paged, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/tauri-wallet/src-tauri/src/operations/account.rs b/tauri-wallet/src-tauri/src/operations/account.rs index 95416fcb0d..675fdf2b61 100644 --- a/tauri-wallet/src-tauri/src/operations/account.rs +++ b/tauri-wallet/src-tauri/src/operations/account.rs @@ -16,7 +16,7 @@ pub struct Account { contract_address: String, client_address: String, denom: Denom, - mnemonmic: Option, + mnemonic: Option, } #[derive(TS, Serialize, Deserialize)] @@ -54,7 +54,7 @@ pub async fn connect_with_mnemonic( contract_address, client_address, denom: Denom::from_str(&denom.to_string())?, - mnemonmic: None, + mnemonic: None, }; let mut w_state = state.write().await; @@ -90,9 +90,9 @@ pub async fn get_balance(state: tauri::State<'_, Arc>>) -> Result< pub async fn create_new_account( state: tauri::State<'_, Arc>>, ) -> Result { - let mnemonic = random_mnemonic(); - let mut client = connect_with_mnemonic(mnemonic.to_string(), state).await?; - client.mnemonmic = Some(mnemonic.to_string()); + let rand_mnemonic = random_mnemonic(); + let mut client = connect_with_mnemonic(rand_mnemonic.to_string(), state).await?; + client.mnemonic = Some(rand_mnemonic.to_string()); Ok(client) } diff --git a/tauri-wallet/src-tauri/src/operations/delegate.rs b/tauri-wallet/src-tauri/src/operations/delegate.rs index 9438b5e7c6..bba966ebec 100644 --- a/tauri-wallet/src-tauri/src/operations/delegate.rs +++ b/tauri-wallet/src-tauri/src/operations/delegate.rs @@ -2,6 +2,9 @@ use crate::coin::Coin; use crate::format_err; use crate::state::State; use cosmwasm_std::Coin as CosmWasmCoin; +use mixnet_contract::{ + Addr, PagedReverseGatewayDelegationsResponse, PagedReverseMixDelegationsResponse, +}; use serde::{Deserialize, Serialize}; use std::convert::TryInto; use std::sync::Arc; @@ -92,3 +95,25 @@ pub async fn undelegate_from_gateway( Err(e) => Err(format_err!(e)), } } + +#[tauri::command] +pub async fn get_reverse_mix_delegations_paged( + state: tauri::State<'_, Arc>>, +) -> Result { + let r_state = state.read().await; + let client = r_state.client()?; + client + .get_reverse_mix_delegations_paged(Addr::unchecked(client.address().as_ref()), None, None) + .await.map_err(|err| format_err!(err)) +} + +#[tauri::command] +pub async fn get_reverse_gateway_delegations_paged( + state: tauri::State<'_, Arc>>, +) -> Result { + let r_state = state.read().await; + let client = r_state.client()?; + client + .get_reverse_gateway_delegations_paged(Addr::unchecked(client.address().as_ref()), None, None) + .await.map_err(|err| format_err!(err)) +} diff --git a/tauri-wallet/src/components/Nav.tsx b/tauri-wallet/src/components/Nav.tsx index 679e0365b3..3e870e4edd 100644 --- a/tauri-wallet/src/components/Nav.tsx +++ b/tauri-wallet/src/components/Nav.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from 'react' +import React, { useContext, useEffect } from 'react' import { Link, useLocation } from 'react-router-dom' import { List, @@ -61,21 +61,13 @@ let routesSchema = [ }, ] -if (process.env.NODE_ENV) { - routesSchema.push({ - label: 'Docs', - route: '/docs', - Icon: , - }) -} - const useStyles = makeStyles((theme: Theme) => ({ navItem: { color: '#fff', - fontSize: 24, + fontSize: 20, }, selected: { - color: theme.palette.primary.main, + color: theme.palette.primary.light, }, })) @@ -84,6 +76,16 @@ export const Nav = () => { const { clientDetails, handleShowAdmin, logOut } = useContext(ClientContext) const location = useLocation() + useEffect(() => { + if (clientDetails?.client_address === ADMIN_ADDRESS) { + routesSchema.push({ + label: 'Docs', + route: '/docs', + Icon: , + }) + } + }, []) + return (
=> export const setContractParams = async ( params: TauriStateParams ): Promise => await invoke('update_state_params', { params }) + +export const getReverseMixDelegations = async (): Promise => + await invoke('get_reverse_mix_delegations_paged') + +export const getReverseGatewayDelegations = async (): Promise => + await invoke('get_reverse_gateway_delegations_paged') diff --git a/tauri-wallet/src/routes/delegate/DelegateForm.tsx b/tauri-wallet/src/routes/delegate/DelegateForm.tsx index fb32dc2c44..50fb7a4929 100644 --- a/tauri-wallet/src/routes/delegate/DelegateForm.tsx +++ b/tauri-wallet/src/routes/delegate/DelegateForm.tsx @@ -74,7 +74,7 @@ export const DelegateForm = ({ }) .then((res) => { onSuccess( - `Successfully delegated ${data.amount} punk to ${res.source_address}` + `Successfully delegated ${data.amount} punk to ${res.target_address}` ) getBalance.fetchBalance() }) diff --git a/tauri-wallet/src/routes/delegate/index.tsx b/tauri-wallet/src/routes/delegate/index.tsx index f329e6c126..729e85cdd0 100644 --- a/tauri-wallet/src/routes/delegate/index.tsx +++ b/tauri-wallet/src/routes/delegate/index.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState } from 'react' import { Box, Button, CircularProgress, Theme } from '@material-ui/core' import { useTheme } from '@material-ui/styles' +import { Alert, AlertTitle } from '@material-ui/lab' import { DelegateForm } from './DelegateForm' import { Layout } from '../../layouts' import { NymCard } from '../../components' @@ -8,7 +9,6 @@ import { EnumRequestStatus, RequestStatus, } from '../../components/RequestStatus' -import { Alert, AlertTitle } from '@material-ui/lab' import { TFee } from '../../types' import { getGasFee } from '../../requests' @@ -73,7 +73,8 @@ export const Delegate = () => { status={status} Error={ - An error occurred with the request: {message} + An error occurred with the request: + {message} } Success={ diff --git a/tauri-wallet/src/routes/internal-docs/index.tsx b/tauri-wallet/src/routes/internal-docs/index.tsx index f7cdc36375..803fecf628 100644 --- a/tauri-wallet/src/routes/internal-docs/index.tsx +++ b/tauri-wallet/src/routes/internal-docs/index.tsx @@ -1,10 +1,12 @@ -import React, { useState } from 'react' +import React, { useContext, useState } from 'react' import { NymCard } from '../../components' import { ApiList } from './ApiList' import { Layout } from '../../layouts' +import { ADMIN_ADDRESS, ClientContext } from '../../context/main' export const InternalDocs = () => { - if (process.env.NODE_ENV == 'development') { + const { clientDetails } = useContext(ClientContext) + if (clientDetails?.client_address === ADMIN_ADDRESS) { return ( diff --git a/tauri-wallet/src/routes/sign-in.tsx b/tauri-wallet/src/routes/sign-in.tsx index 6ef052ef41..d80a81060f 100644 --- a/tauri-wallet/src/routes/sign-in.tsx +++ b/tauri-wallet/src/routes/sign-in.tsx @@ -202,7 +202,6 @@ const CreateAccountContent = ({ showSignIn }: { showSignIn: () => void }) => { setIsLoading(false) }, 2500) } catch (e: any) { - console.log(e) setError(e) } } @@ -210,7 +209,7 @@ const CreateAccountContent = ({ showSignIn }: { showSignIn: () => void }) => { Create wallet - Create an new wallet to start using the Nym network + Create a new wallet to start using the Nym network void onSuccess: (message?: string) => void }) => { const { + control, handleSubmit, - register, setValue, watch, formState: { errors, isSubmitting }, @@ -47,22 +50,27 @@ export const UndelegateForm = ({ resolver: yupResolver(validationSchema), }) const watchNodeType = watch('nodeType') + + useEffect(() => { + setValue('identity', '') + }, [watchNodeType]) + const { getBalance } = useContext(ClientContext) + const theme: Theme = useTheme() + const onSubmit = async (data: TFormData) => { await undelegate({ type: data.nodeType, identity: data.identity, }) .then(async (res) => { - onSuccess(`Successfully undelegated from ${res.source_address}`) + onSuccess(`Successfully undelegated from ${res.target_address}`) getBalance.fetchBalance() }) .catch((e) => onError(e)) } - const theme: Theme = useTheme() - return (
@@ -72,6 +80,7 @@ export const UndelegateForm = ({ setValue('nodeType', nodeType)} + disabled={isSubmitting} /> @@ -85,26 +94,35 @@ export const UndelegateForm = ({ - ( + setValue('identity', value || '')} + options={ + watchNodeType === EnumNodeType.mixnode + ? delegations.mixnodes.delegated_nodes + : delegations.gateways.delegated_nodes + } + renderInput={(params) => ( + + )} + /> + )} /> - - {/* {allocationWarning && ( - - - {allocationWarning} - - - )} */}
{ const [message, setMessage] = useState() - const [status, setStaus] = useState( + const [status, setStatus] = useState( EnumRequestStatus.initial ) const [isLoading, setIsLoading] = useState(true) const [fees, setFees] = useState() + const [delegations, setDelegations] = useState() useEffect(() => { - const getFees = async () => { - const mixnode = await getGasFee('UndelegateFromMixnode') - const gateway = await getGasFee('UndelegateFromGateway') + initialize() + }, []) + + const initialize = async () => { + setIsLoading(true) + + try { + const [mixnodeFee, gatewayFee, mixnodeDelegations, gatewayDelegations] = + await Promise.all([ + getGasFee('UndelegateFromMixnode'), + getGasFee('UndelegateFromGateway'), + getReverseMixDelegations(), + getReverseGatewayDelegations(), + ]) setFees({ - mixnode: mixnode, - gateway: gateway, + mixnode: mixnodeFee, + gateway: gatewayFee, }) - setIsLoading(false) + + setDelegations({ + mixnodes: mixnodeDelegations, + gateways: gatewayDelegations, + }) + } catch { + setStatus(EnumRequestStatus.error) + setMessage('An error occured when initialising the page') } - getFees() - }, []) + setIsLoading(false) + } const theme: Theme = useTheme() @@ -55,35 +83,57 @@ export const Undelegate = () => { )} <> - {status === EnumRequestStatus.initial && fees && ( + {status === EnumRequestStatus.initial && fees && delegations && ( { setMessage(message) - setStaus(EnumRequestStatus.error) + setStatus(EnumRequestStatus.error) }} onSuccess={(message) => { setMessage(message) - setStaus(EnumRequestStatus.success) + setStatus(EnumRequestStatus.success) }} /> )} {status !== EnumRequestStatus.initial && ( - - An error occurred with the request: {message} - - } - Success={ - - {' '} - Undelegation complete - {message} - - } - /> + <> + + An error occurred with the request: {message} + + } + Success={ + + {' '} + Undelegation complete + {message} + + } + /> +
+ +
+ )} diff --git a/tauri-wallet/src/types/global.ts b/tauri-wallet/src/types/global.ts index 672f1629d6..b8771a2e4e 100644 --- a/tauri-wallet/src/types/global.ts +++ b/tauri-wallet/src/types/global.ts @@ -24,3 +24,9 @@ export type TCreateAccount = { } & TSignInWithMnemonic export type TFee = { [key in EnumNodeType]: Coin } + +export type TDelegation = { + delegated_nodes: string[] + delegation_owner: string + start_next_after: string +} diff --git a/tauri-wallet/src/types/rust/account.ts b/tauri-wallet/src/types/rust/account.ts index d826983913..196968055f 100644 --- a/tauri-wallet/src/types/rust/account.ts +++ b/tauri-wallet/src/types/rust/account.ts @@ -4,5 +4,5 @@ export interface Account { contract_address: string; client_address: string; denom: Denom; - mnemonmic: string | null; + mnemonic: string | null; } \ No newline at end of file diff --git a/tauri-wallet/src/types/rust/stateparams.ts b/tauri-wallet/src/types/rust/stateparams.ts index b7dbabc531..f0c18aa83e 100644 --- a/tauri-wallet/src/types/rust/stateparams.ts +++ b/tauri-wallet/src/types/rust/stateparams.ts @@ -7,5 +7,4 @@ export interface TauriStateParams { mixnode_delegation_reward_rate: string; gateway_delegation_reward_rate: string; mixnode_active_set_size: number; - gateway_active_set_size: number; } \ No newline at end of file