Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 9cf0768
Author: 0o-de-lally <>
Date:   Tue Dec 5 12:31:58 2023 -0500

    extra attempt to parse v5 address on transfer

commit 37d60eb
Author: 0o-de-lally <>
Date:   Tue Dec 5 12:04:29 2023 -0500

    update dep: keyring

commit 51d0934
Author: 0o-de-lally <>
Date:   Tue Dec 5 11:40:38 2023 -0500

    miner progress bar FML

commit 086bc5e
Author: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com>
Date:   Sat Dec 2 20:12:22 2023 -0500

    lint

commit e51ea6d
Author: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com>
Date:   Sat Dec 2 20:11:24 2023 -0500

    don't destroy miner interval when leaving miner page
  • Loading branch information
0o-de-lally committed Dec 5, 2023
1 parent 04a5683 commit 9ab748a
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src-tauri/Cargo.lock

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

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ url = { version = "2.2.2", features = ["serde"] }

# only in carpe
directories = "5.0.1"
keyring = "0.10.1"
keyring = "^1.2"
simplelog = { version = "^0.11.0", features = ["paris"] }
tauri = { version = "^1.5.2", features = ["api-all", "updater"] }

Expand Down
16 changes: 14 additions & 2 deletions src-tauri/src/commands/tx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! transaction scripts
use std::str::FromStr;

use crate::key_manager::{get_private_key, inject_private_key_to_cfg};
use crate::{carpe_error::CarpeError, configs::get_cfg};

Expand All @@ -13,13 +15,23 @@ fn make_account_key(address: &AccountAddress) -> anyhow::Result<AccountKey> {
#[tauri::command(async)]
pub async fn coin_transfer(
_sender: AccountAddress,
receiver: AccountAddress,
receiver: &str,
amount: u64,
) -> Result<(), CarpeError> {
// NOTE: unsure Serde was catching all cases check serialization
let receiver_account = match AccountAddress::from_str(receiver) {
Ok(a) => a,
Err(e) => {
dbg!(e);
// try prepending
AccountAddress::from_str(&format!("0x{}", receiver))?
}
};

let mut config = get_cfg()?;
inject_private_key_to_cfg(&mut config)?;
let mut sender = Sender::from_app_cfg(&config, None).await?;
sender.transfer(receiver, amount as f64, false).await?;
sender.transfer(receiver_account, amount as f64, false).await?;
Ok(())
}

Expand Down
9 changes: 4 additions & 5 deletions src-tauri/src/key_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use libra_types::exports::AccountAddress;
use libra_types::legacy_types::app_cfg::AppCfg;

use anyhow::{anyhow, bail};
use keyring::KeyringError;
use libra_types::exports::{Ed25519PrivateKey, Ed25519PublicKey, KeyPair};

use crate::carpe_error::{CarpeError, ErrorCat, E_KEY_NOT_REGISTERED};
Expand All @@ -18,7 +17,7 @@ const KEYRING_APP_NAME: &str = "carpe";
/// overwrite then delete
pub fn erase_keyring_address(address: AccountAddress) -> anyhow::Result<()> {
let addr_str = &address.to_string();
let kr = keyring::Keyring::new(KEYRING_APP_NAME, addr_str);
let kr = keyring::Entry::new(KEYRING_APP_NAME, addr_str);

let bytes = &[0u8, 64];
let encoded = hex::encode(bytes);
Expand All @@ -28,8 +27,8 @@ pub fn erase_keyring_address(address: AccountAddress) -> anyhow::Result<()> {
Ok(())
}
/// send the encoded private key to OS keyring
pub fn set_private_key(ol_address: &str, key: Ed25519PrivateKey) -> Result<(), KeyringError> {
let kr = keyring::Keyring::new(KEYRING_APP_NAME, ol_address);
pub fn set_private_key(ol_address: &str, key: Ed25519PrivateKey) -> Result<(), keyring::Error> {
let kr = keyring::Entry::new(KEYRING_APP_NAME, ol_address);

let bytes: &[u8] = &(key.to_bytes());
let encoded = hex::encode(bytes);
Expand All @@ -40,7 +39,7 @@ pub fn set_private_key(ol_address: &str, key: Ed25519PrivateKey) -> Result<(), K
/// retrieve a private key from OS keyring
pub fn get_private_key(address: &AccountAddress) -> Result<Ed25519PrivateKey, anyhow::Error> {
let ol_address = address.to_string();
let kr = keyring::Keyring::new(KEYRING_APP_NAME, &ol_address);
let kr = keyring::Entry::new(KEYRING_APP_NAME, &ol_address);
match kr.get_password() {
Ok(s) => {
let ser = hex::decode(s)?;
Expand Down
22 changes: 2 additions & 20 deletions src/components/miner/ToggleMiner.svelte
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte'
import { toggleMining } from '../../modules/miner_toggle'
import { minerLoopEnabled } from '../../modules/miner'
import { setProofPercent } from '../../modules/miner_invoke'
let enabled: boolean
let unsubscribe
let looper
onMount(async () => {
unsubscribe = minerLoopEnabled.subscribe((boo) => (enabled = boo))
// for safety clear the interval
clearInterval(looper)
looper = setInterval(() => setProofPercent(), 1000)
})
onDestroy(async () => {
clearInterval(looper)
unsubscribe && unsubscribe()
})
import { toggleMining } from '../../modules/miner_toggle'
</script>

<main>
<div class="uk-text-center uk-margin" style="position: relative">
<label class="uk-switch">
<input type="checkbox" on:click={() => toggleMining()} checked={enabled} />
<input type="checkbox" on:click={() => toggleMining()} checked={$minerLoopEnabled} />
<div class="uk-switch-slider uk-switch-on-off round" />
</label>
</div>
Expand Down
6 changes: 1 addition & 5 deletions src/components/txs/Transactions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type { CarpeProfile } from '../../modules/accounts'
import { raise_error } from '../../modules/carpeError'
import CantStart from '../miner/cards/CantStart.svelte'
import UIkit from 'uikit'
const errorDic = {
'120127': $_('txs.transfer.error_slow_wallet'),
Expand Down Expand Up @@ -63,12 +64,7 @@
notify_success($_('txs.transfer.success'))
waitingTxs = false
amount = 0
// amountFormatted = ''
receiver = null
// callback
// onSuccess();
// close modal
// UIkit.modal('#coinTransferDialog').hide();
})
.catch((error) => {
responses.set(JSON.stringify(error))
Expand Down
7 changes: 6 additions & 1 deletion src/modules/accountActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { get } from 'svelte/store'
import { invoke } from '@tauri-apps/api/tauri'
import { raise_error, type CarpeError, logger, Level } from './carpeError'
import { responses } from './debug'
import { minerLoopEnabled } from './miner'
import { isTowerNewbie, minerLoopEnabled, resetTowerStatus } from './miner'

import { notify_success, notify_error } from './carpeNotify'
import {
Expand Down Expand Up @@ -142,6 +142,11 @@ export const setAccount = async (account: string, notifySucess = true) => {
.catch((e) => {
raise_error(e, false, 'setAccount')
})
.finally(() => {
//need to reset, otherwise may be looking at wrong account
resetTowerStatus()
isTowerNewbie.set(true)
})
}

// export function addNewAccount(account: Profile) {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/carpeNotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export function notify_error(s: string) {
message: `<span uk-icon=icon: warning></span> ${s}`,
pos: 'bottom-left',
status: 'danger',
timeout: 15000,
timeout: 10000,
})
}
4 changes: 0 additions & 4 deletions src/modules/miner_invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,6 @@ export const getTowerChainView = async () => {
isRefreshingAccounts.set(false)
})
.catch((e) => {
//need to reset, otherwise may be looking at wrong account
resetTowerStatus()
isTowerNewbie.set(true)

raise_error(e, true, 'getTowerChainView')
isRefreshingAccounts.set(false)
})
Expand Down
13 changes: 12 additions & 1 deletion src/modules/miner_toggle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { get } from 'svelte/store'
import { minerLoopEnabled } from './miner'
import { killBacklogListener, startBacklogListener, maybeTowerOnce } from './miner_invoke'
import {
killBacklogListener,
startBacklogListener,
maybeTowerOnce,
setProofPercent,
} from './miner_invoke'
import { carpeTick } from './tick'

let looper

export const enableMining = async (): Promise<void> => {
if (!get(minerLoopEnabled)) {
// When the user turns on the toggle, they will be prompted for OS password.
Expand All @@ -14,10 +21,13 @@ export const enableMining = async (): Promise<void> => {
// we should only ask for this once. We ask for it when the user toggles the miner.
// if the user has stuck proofs, we will show an error screen with a button for
// manually triggering the backlog.

startBacklogListener()
.then(carpeTick)
.then(() => minerLoopEnabled.set(true))
.then(maybeTowerOnce)

looper = setInterval(() => setProofPercent(), 5000)
}
}

Expand All @@ -26,6 +36,7 @@ export async function disableMining(): Promise<boolean> {
// set mining to disabled
minerLoopEnabled.set(false)
killBacklogListener() // TODO: how do we prevent zombie listeners from making duplicates.
clearInterval(looper)
return true
}

Expand Down
1 change: 1 addition & 0 deletions src/modules/tick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const carpeTick = async () => {
// things that need network connectivity e.g. miner happen here
getMetadata()
.then(refreshAccounts)
// tower things
.then(getTowerChainView)
.then(getLocalHeight)
.then(maybeEmitBacklog)
Expand Down
10 changes: 9 additions & 1 deletion src/style/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ input:checked + .uk-switch-slider.uk-switch-big:before {
text-align: center;
}

.uk-notification-message-error {
.uk-notification-message-danger {
color: #f8f8f8 !important;
background-color: #f0506e !important;
}
Expand All @@ -98,3 +98,11 @@ input:checked + .uk-switch-slider.uk-switch-big:before {
color: #f8f8f8 !important;
background-color: #32d296 !important;
}

.uk-notification-close {
color: #f8f8f8 !important;
}

.uk-progress {
background-color: #dae9f7 !important;
}

0 comments on commit 9ab748a

Please sign in to comment.