Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue of automatic network connection #278

Merged
merged 7 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/img/slowwallet-step-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/slowwallet-step-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/slowwallet-step-done.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/slowwallet-step-success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,29 @@ To start mining, just click on the red toggle button, so it turns into green col
## DANGER

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!***

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

![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

![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.


2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
[package]
name = "carpe"
version = "1.0.4"
version = "1.0.5"
authors = ["0LNetworkCommunity"]
default-run = "carpe"
description = "a light miner and wallet for libra"
Expand Down
2 changes: 1 addition & 1 deletion src/components/wallet/Actions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{#if res}
<h4 class="uk-text-light uk-text-uppercase uk-text-muted uk-text-thin">{$_('wallet.settings.slow_label')}</h4>
<p>{$_('wallet.settings.slow_info')}</p>
{:else if !$signingAccount.watch_only}
{:else if !$signingAccount.watch_only && $signingAccount.on_chain }
<SetWalletType />
{/if}
{/await}
Expand Down
49 changes: 25 additions & 24 deletions src/components/wallet/Keygen.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<script lang="ts">
import { _ } from 'svelte-i18n'
import { invoke } from '@tauri-apps/api/tauri'
import { signingAccount } from '../../modules/accounts'
import { tempCreateAccount } from '../../modules/accounts'
import type { CarpeProfile } from '../../modules/accounts'
import { minerLoopEnabled } from '../../modules/miner'
// import { minerLoopEnabled } from '../../modules/miner'

import { raise_error } from '../../modules/carpeError'
import { responses } from '../../modules/debug'
import AccountFromMnemSubmit from './AccountFromMnemSubmit.svelte'
import { onDestroy } from 'svelte'
import { get } from 'svelte/store'
// import { get } from 'svelte/store'

interface NewKeygen {
entry: CarpeProfile
Expand All @@ -25,16 +25,16 @@
tempDangerDisplayMnem = res.mnem
res.mnem = null
responses.set(JSON.stringify(res))
// cannot switch profile with miner running
if (!get(minerLoopEnabled)) {
signingAccount.set(res.entry)
}
tempCreateAccount.set(res.entry)
hide = false
})
.catch((e) => raise_error(e, true, 'do_keygen'))
}

onDestroy(() => (tempDangerDisplayMnem = null))
onDestroy(() => {
tempDangerDisplayMnem = null
tempCreateAccount.set(null)
})
</script>

<main>
Expand All @@ -44,10 +44,10 @@
</h3>
</div> -->

{#if $signingAccount && $signingAccount.account && !hide}
{#if $tempCreateAccount && $tempCreateAccount.account && !hide}
<div class="uk-margin uk-card uk-card-default uk-card-body uk-text-muted">
<h5 class="uk-text-muted uk-text-uppercase">{$_('wallet.keygen.account_address')}</h5>
<p class="uk-text-emphasis uk-text-uppercase">{$signingAccount.account}</p>
<p class="uk-text-emphasis uk-text-uppercase">{$tempCreateAccount.account}</p>

<h5 class="uk-text-muted uk-text-uppercase uk-text-danger">
{$_('wallet.keygen.securite_recovery_phrase')}
Expand All @@ -74,24 +74,25 @@
</button>
</div>
{:else}

<div class="uk-card uk-card-default uk-align-center uk-width-1-2@m">
<div class="uk-card-header">
<div class="uk-card uk-card-default uk-align-center uk-width-1-2@m">
<div class="uk-card-header">
<div class="uk-grid-small uk-flex-middle" uk-grid>
<div class="uk-width-expand">
<h3 class="uk-card-title uk-margin-remove-bottom uk-text-muted uk-text-uppercase">{$_('wallet.keygen.title')}</h3>
</div>
<div class="uk-width-expand">
<h3 class="uk-card-title uk-margin-remove-bottom uk-text-muted uk-text-uppercase">
{$_('wallet.keygen.title')}
</h3>
</div>
</div>
</div>
<div class="uk-card-body">
</div>
<div class="uk-card-body">
<p>{$_('wallet.keygen.description')}</p>
</div>
<div class="uk-card-footer">
<button class="uk-button uk-button-secondary" on:click={do_keygen}
>{$_('wallet.keygen.btn_generate_keys')}</button
>
</div>
</div>
<div class="uk-card-footer">

<button class="uk-button uk-button-secondary" on:click={do_keygen}>{$_('wallet.keygen.btn_generate_keys')}</button>
</div>
</div>


<!-- <div class="uk-card uk-card-default uk-card-body">
<div class="uk-flex uk-child-width-1-2">
Expand Down
7 changes: 3 additions & 4 deletions src/components/wallet/Wallet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { _ } from 'svelte-i18n'
import UIkit from 'uikit'
import Icons from 'uikit/dist/js/uikit-icons'
import { allAccounts } from '../../modules/accounts'
import { allAccounts, pendingAccounts } from '../../modules/accounts'

// views
import Newbie from './Newbie.svelte'
Expand All @@ -13,7 +13,6 @@

UIkit.use(Icons)

let pendingAccounts = $allAccounts.filter((x) => x && !x.on_chain)
</script>

<main>
Expand All @@ -30,8 +29,8 @@
<AccountsList />
<CreateAccountLinks />

{#if $connected && pendingAccounts.length > 0}
<ReminderCreate {pendingAccounts} isConnected={$connected} />
{#if $connected && $pendingAccounts.length > 0}
<ReminderCreate pendingAccounts={$pendingAccounts} isConnected={$connected} />
{/if}
{/if}
</div>
Expand Down
52 changes: 49 additions & 3 deletions src/modules/accountActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ import {
migrateSuccess,
canMigrate,
watchAccounts,
pendingAccounts,
isCarpeTickRunning,
} from './accounts'
import type { CarpeProfile, SlowWalletBalance } from './accounts'
import { navigate } from 'svelte-navigator'
import { carpeTick } from './tick'
import { initNetwork } from './networks'

allAccounts.subscribe((v) => {
pendingAccounts.set(v.filter((x) => x && !x.on_chain))
})
export const getDefaultProfile = async () => {
invoke('get_default_profile', {})
.then((res: CarpeProfile) => {
Expand Down Expand Up @@ -62,7 +67,22 @@ export const refreshAccounts = async () => {
allAccounts.set(result)
const currentAccount = get(signingAccount)
if (currentAccount) {
signingAccount.set(get(allAccounts).find((item) => item.account === currentAccount.account))
const changedCurrentAccount = get(allAccounts).find((item) => {
const {
account,
on_chain,
balance: { unlocked, total },
} = item
return (
account === currentAccount.account &&
(on_chain !== currentAccount.on_chain ||
unlocked !== currentAccount.balance?.unlocked ||
total !== currentAccount.balance?.total)
)
})
if (changedCurrentAccount) {
signingAccount.set(changedCurrentAccount)
}
}
if (!get(isAccountRefreshed)) {
isAccountRefreshed.set(true)
Expand Down Expand Up @@ -96,6 +116,14 @@ export const addAccount = async (init_type: InitType, secret: string) => {
// submit
return invoke(method_name, arg_obj)
.then(async (res: CarpeProfile) => {
// update watchAccounts

let list = get(watchAccounts)
list = list.filter((item) => item !== res.account)
watchAccounts.set(list)
localStorage.setItem('watchAccounts', JSON.stringify(list))
res.watch_only = false

await onAccountAdd(res)
return res
})
Expand Down Expand Up @@ -350,6 +378,19 @@ export function getPrivateKey(address: string, callback = null) {
}

export function addWatchAccount(address: string) {
const accountList: CarpeProfile[] = get(allAccounts)
// v5 address padding 0
if (address.length == 32) {
address = address.padStart(64, '0')
}
const hasAdd = !!accountList.find(
(item) => item.account.toLocaleLowerCase() === address.toLocaleLowerCase(),
)
if (hasAdd) {
notify_error('address already exists')
return
}

invoke('add_watch_account', {
address,
})
Expand All @@ -359,6 +400,7 @@ export function addWatchAccount(address: string) {
watchAccounts.set(list)
localStorage.setItem('watchAccounts', JSON.stringify(list))
res.watch_only = true

await onAccountAdd(res)
})
.catch((e: CarpeError) => {
Expand All @@ -376,9 +418,13 @@ async function onAccountAdd(res: CarpeProfile) {
signingAccount.set(res)
}
await initNetwork()
if (!get(isCarpeTickRunning)) {
// start the carpe tick for every 30 secs, this is async
setInterval(carpeTick, 30000)
isCarpeTickRunning.set(true)
}
// only navigate away once we have refreshed the accounts including balances
notify_success(`Account Added: ${res.nickname}`)

await refreshAccounts()
setTimeout(() => navigate('wallet'), 10)
await refreshAccounts().finally(() => navigate('wallet'))
}
2 changes: 1 addition & 1 deletion src/modules/accountTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const setWalletType = async (wtype: WalletType) => {

invoke('set_slow_wallet')
.then((res: string) => {
notify_success(`The account is set to: ${wtype.toString()}`)
notify_success(`The account is set to: SlowWallet`)
responses.set(res)
})
.catch((e: CarpeError) => {
Expand Down
4 changes: 3 additions & 1 deletion src/modules/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ export const signingAccount = writable<CarpeProfile>()
export const isInit = writable(false)
export const isRefreshingAccounts = writable(false)
export const allAccounts = writable<CarpeProfile[]>([])
export const pendingAccounts = writable<CarpeProfile[]>([])
export const isAccountRefreshed = writable(false)
export const accountEvents = writable<object>() // TODO define interface AccountEvent
export const isKeyError = writable<boolean>(false)
export const makeWhole = writable<object>()

export const tempCreateAccount = writable<CarpeProfile>()
export const canMigrate = writable<boolean>(false)
export const migrateSuccess = writable<boolean>()
export const migrateInProgress = writable<boolean>()
export const isCarpeTickRunning = writable<boolean>(false)

const localeWatchAccounts = JSON.parse(localStorage.getItem('watchAccounts') || '[]')
export const watchAccounts = writable<string[]>(localeWatchAccounts)
Expand Down
2 changes: 2 additions & 0 deletions src/modules/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getMetadata, getNetwork, refreshUpstreamPeerStats, initNetwork } from '
import { getVersion } from './version'
import { carpeTick } from './tick'
import { writable } from 'svelte/store'
import { isCarpeTickRunning } from './accounts'

export const isBooted = writable(false)

Expand All @@ -36,6 +37,7 @@ export const bootUp = async () => {
.finally(() => {
refreshUpstreamPeerStats()
setInterval(carpeTick, 30000) // start the carpe tick for every 30 secs, this is async
isCarpeTickRunning.set(true)
isBooted.set(true)
navigate('wallet')
})
Expand Down
Loading