Skip to content

Commit

Permalink
Fix Onboarding and Navigation Tab Visibility in Carpe (#304)
Browse files Browse the repository at this point in the history
* adds account skeleton for new accounts while loading info
removes tabs when all accounts are removed

* fixes lint errors

* lint fixes
  • Loading branch information
soaresa authored May 27, 2024
1 parent 16c4230 commit 1fb2601
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 228 deletions.
34 changes: 16 additions & 18 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ on:
branches:
- 'release**'
- 'main'

jobs:
build:
build:
strategy:
fail-fast: false
matrix:
os: [ windows-latest, macos-11, ubuntu-latest ]
os: [windows-latest, macos-11, ubuntu-latest]
name: build ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -29,10 +29,10 @@ jobs:
uses: actions/checkout@v4.1.1
with:
fetch-depth: 0

- name: Set rust_version from rust_toolchain file
run: echo "RUST_VERSION=$(cat src-tauri/rust-toolchain)" >> $GITHUB_ENV

- name: Set rust_version from rust_toolchain file
if: matrix.os == 'windows-latest'
run: |
Expand All @@ -42,9 +42,9 @@ jobs:
- uses: actions-rs/toolchain@v1.0.6
with:
profile: minimal
toolchain: "${{ env.RUST_VERSION }}"
toolchain: '${{ env.RUST_VERSION }}'
override: true

# Setup Node.js
- name: setup node
uses: actions/setup-node@v4.0.2
Expand All @@ -60,7 +60,7 @@ jobs:
if: matrix.os == 'windows-latest'
uses: KyleMayes/install-llvm-action@v1
with:
version: "11.0"
version: '11.0'
directory: ${{ runner.temp }}/llvm

- name: Set LIBCLANG_PATH
Expand All @@ -74,17 +74,15 @@ jobs:
$var = (get-item $(rustup which rustc)).Directory.Parent.FullName+ '\lib\rustlib\' + (rustc -vV | findstr "host:*").split(':')[1].Trim() + '\lib'
Copy-Item ('${{ github.workspace }}' + '\redist' + '\x86_64\*') -Destination $var -Recurse
######## CACHE ########
######## CACHE ########

- uses: Swatinem/rust-cache@v2
with:
workspaces: ./src-tauri
shared-key: "${{ matrix.os }}"
cache-on-failure: true

workspaces: ./src-tauri
shared-key: '${{ matrix.os }}'
cache-on-failure: true

######## BUILD ########
######## BUILD ########

- name: yarn installation
run: yarn install
Expand All @@ -96,6 +94,6 @@ jobs:
- name: build tauri
run: yarn run build:github-pr
env:
# Mocked keys.
TAURI_PRIVATE_KEY: "dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5ZUYrUFF0RS9ZbU5EN0VFWk52TmpDRDQvTFFWOHhqSXNkZFVvUjZSRWNJc0FBQkFBQUFBQUFBQUFBQUlBQUFBQTZhNUxkYVFJWDNWTENKR2tSNzFVcDhsRzcvd0lKeWRGcytBZDNyZ3o3OWRXOWVmbmZCQktJYk8xOHVHWG5CZ25XN1pBOXM3SjMyWW1DRFNZWFJ5WGxsd3B6d3RvOEtTNHFFbFM5VE5obmNEZ1dHeEljVFRhZ2FXa0RzNHZOVkNESE5DdDArUmkvUUE9Cg=="
TAURI_KEY_PASSWORD: "mock"
# Mocked keys.
TAURI_PRIVATE_KEY: 'dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5ZUYrUFF0RS9ZbU5EN0VFWk52TmpDRDQvTFFWOHhqSXNkZFVvUjZSRWNJc0FBQkFBQUFBQUFBQUFBQUlBQUFBQTZhNUxkYVFJWDNWTENKR2tSNzFVcDhsRzcvd0lKeWRGcytBZDNyZ3o3OWRXOWVmbmZCQktJYk8xOHVHWG5CZ25XN1pBOXM3SjMyWW1DRFNZWFJ5WGxsd3B6d3RvOEtTNHFFbFM5VE5obmNEZ1dHeEljVFRhZ2FXa0RzNHZOVkNESE5DdDArUmkvUUE9Cg=='
TAURI_KEY_PASSWORD: 'mock'
8 changes: 4 additions & 4 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ jobs:
uses: actions/checkout@v4.1.1
with:
fetch-depth: 0

- name: Set rust_version from rust_toolchain file
run: echo "RUST_VERSION=$(cat src-tauri/rust-toolchain)" >> $GITHUB_ENV

- uses: actions-rs/toolchain@v1.0.6
with:
profile: minimal
Expand All @@ -59,10 +59,10 @@ jobs:
with:
shared-key: 'libra' # to share across CI builds, so it is not job-id specific
cache-on-failure: true

- name: check format
working-directory: ./src-tauri
run: cargo fmt --all -- --check
run: cargo fmt --all -- --check

- name: lint
working-directory: ./src-tauri
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ windows-latest, macos-11, ubuntu-latest ]
os: [windows-latest, macos-11, ubuntu-latest]
name: build ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -58,9 +58,9 @@ jobs:

- uses: Swatinem/rust-cache@v2
with:
workspaces: ./src-tauri
shared-key: "${{ matrix.os }}"
cache-on-failure: true
workspaces: ./src-tauri
shared-key: '${{ matrix.os }}'
cache-on-failure: true

######## BUILD ########

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Currently Windows and Mac are supported:

- [Download MacOs 11+](https://github.com/0LNetworkCommunity/carpe/releases/download/v1.0.7/carpe_1.0.7_x64.dmg)


# About

Carpe is a desktop "wallet" that connects to the 0L network and lets you create accounts, do some account management. To learn more about 0L itself, you can check out the official website of the project : [0L Network website](https://0l.network/).
Expand Down
11 changes: 5 additions & 6 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,26 @@ If you don't yet have a friend on 0L, come to the [Discord Server](https://disco
There are some dangerous buttons on the "TRANSACTIONS" and "SETTINGS" screens. Don't use them until you know what they do.

## SlowWallet

How to set your wallet as a slow wallet
**Wallet balance must be maintained at least 10 Libra**

***Note that this operation is irreversible, please do not use this feature unless you know what you are doing!***
**_Note that this operation is irreversible, please do not use this feature unless you know what you are doing!_**

Click on the Settings icon to the left of the wallet address you want to set.

![screen01](./img/slowwallet-step-1.jpg)

If you already have a slow wallet, clicking on the Settings icon will show you the following image
If you already have a slow wallet, clicking on the Settings icon will show you the following image

![screen3](./img/slowwallet-step-done.png)

If it is not a slow wallet, click on the setup icon will be displayed as shown below, then click on the `SET SLOW WALLET` button, the system pops up the authorization, waiting for a successful transaction
If it is not a slow wallet, click on the setup icon will be displayed as shown below, then click on the `SET SLOW WALLET` button, the system pops up the authorization, waiting for a successful transaction

![screen02](./img/slowwallet-step-2.jpg)

![screen01](./img/keyring.png)

![screen02](./img/slowwallet-step-success.png)

If you have any problems with the process, please feel free to come to [Discord Server](https://discord.gg/AzCp63pggW) for feedback.


If you have any problems with the process, please feel free to come to [Discord Server](https://discord.gg/AzCp63pggW) for feedback.
2 changes: 1 addition & 1 deletion src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pub(crate) mod networks;
pub(crate) mod preferences;
pub(crate) mod query;
pub(crate) mod tx;
pub(crate) mod user_preferences;
pub(crate) mod wallets;
pub(crate) mod web_logs;
pub(crate) mod user_preferences;

//pub use app_version::*;
94 changes: 55 additions & 39 deletions src-tauri/src/commands/user_preferences.rs
Original file line number Diff line number Diff line change
@@ -1,61 +1,77 @@
use crate::carpe_error::CarpeError;
use crate::configs::default_config_path;
use serde::{Deserialize, Serialize};
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::path::{PathBuf};
use crate::configs::default_config_path;
use std::path::PathBuf;

#[derive(Serialize, Deserialize)]
pub struct UserPreferences {
accounts_list_sort_column: Option<String>,
accounts_list_sort_order: Option<String>,
accounts_list_sort_column: Option<String>,
accounts_list_sort_order: Option<String>,
}

// Utility function to retrieve the full path to the preferences file
fn get_preferences_path() -> Result<PathBuf, CarpeError> {
let app_dir_path = default_config_path(); // Assuming this returns a PathBuf or Path
let app_dir_path = default_config_path(); // Assuming this returns a PathBuf or Path

// Check if the path exists, if not, return an error
if !app_dir_path.exists() {
return Err(CarpeError::misc("App directory not found"));
}
// Check if the path exists, if not, return an error
if !app_dir_path.exists() {
return Err(CarpeError::misc("App directory not found"));
}

Ok(app_dir_path.join("user_preferences.json"))
Ok(app_dir_path.join("user_preferences.json"))
}

#[tauri::command(async)]
pub async fn get_user_preferences() -> Result<UserPreferences, CarpeError> {
let file_path = get_preferences_path()?;
match File::open(&file_path) {
Ok(mut file) => {
let mut contents = String::new();
if let Err(e) = file.read_to_string(&mut contents) {
return Err(CarpeError::misc(&format!("Failed to read from preferences file: {}", e)));
}
serde_json::from_str(&contents).map_err(|e| CarpeError::misc(&format!("Failed to parse preferences: {}", e)))
},
Err(e) => Err(CarpeError::misc(&format!("Failed to open preferences file: {}", e))),
let file_path = get_preferences_path()?;
match File::open(file_path) {
Ok(mut file) => {
let mut contents = String::new();
if let Err(e) = file.read_to_string(&mut contents) {
return Err(CarpeError::misc(&format!(
"Failed to read from preferences file: {}",
e
)));
}
serde_json::from_str(&contents)
.map_err(|e| CarpeError::misc(&format!("Failed to parse preferences: {}", e)))
}
Err(e) => Err(CarpeError::misc(&format!(
"Failed to open preferences file: {}",
e
))),
}
}

#[tauri::command(async)]
pub async fn set_accounts_list_preference(sort_column: String, sort_order: String) -> Result<(), CarpeError> {
let file_path = get_preferences_path()?;
let mut file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(&file_path)
.map_err(|e| CarpeError::misc(&format!("Failed to open preferences file for writing: {}", e)))?;

let preferences = UserPreferences {
accounts_list_sort_column: Some(sort_column),
accounts_list_sort_order: Some(sort_order),
};

let serialized_data = serde_json::to_string_pretty(&preferences)
.map_err(|e| CarpeError::misc(&format!("Failed to serialize preferences: {}", e)))?;

file.write_all(serialized_data.as_bytes())
.map_err(|e| CarpeError::misc(&format!("Failed to write preferences file: {}", e)))
pub async fn set_accounts_list_preference(
sort_column: String,
sort_order: String,
) -> Result<(), CarpeError> {
let file_path = get_preferences_path()?;
let mut file = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(file_path)
.map_err(|e| {
CarpeError::misc(&format!(
"Failed to open preferences file for writing: {}",
e
))
})?;

let preferences = UserPreferences {
accounts_list_sort_column: Some(sort_column),
accounts_list_sort_order: Some(sort_order),
};

let serialized_data = serde_json::to_string_pretty(&preferences)
.map_err(|e| CarpeError::misc(&format!("Failed to serialize preferences: {}", e)))?;

file
.write_all(serialized_data.as_bytes())
.map_err(|e| CarpeError::misc(&format!("Failed to write preferences file: {}", e)))
}
Loading

0 comments on commit 1fb2601

Please sign in to comment.