Skip to content

Commit

Permalink
Disable Watch-Only Accounts from Transfer Screen (#302)
Browse files Browse the repository at this point in the history
* forbid watch only account access to transfer screen
sort dropdown accounts lists

* lint fix
  • Loading branch information
soaresa authored May 23, 2024
1 parent caed88d commit 01ef99e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/commands/wallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ pub async fn switch_profile(account: AccountAddress) -> Result<CarpeProfile, Car
app_cfg.save_file()?;

// TODO: gross, fix upstream `app_cfg.rs` to prevent the borrow issues here
let mut profile = app_cfg.get_profile(Some(account.to_string()))?;
let profile = app_cfg.get_profile(Some(account.to_string()))?;

// Assign account note
let mut profiles: Vec<CarpeProfile> = vec![profile.into()];
Expand Down
13 changes: 3 additions & 10 deletions src/components/Nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
]
const location_store = useLocation()
$: watchOnly = $signingAccount?.watch_only
</script>

<main class="uk-margin-top">
Expand All @@ -36,27 +38,18 @@
<li class="uk-padding {$location_store.pathname.includes('wallet') ? 'uk-active' : ''}">
<Link to={routes.wallet}>{$_('nav.wallet')}</Link>
</li>
<!-- <li class="uk-padding {$location_store.pathname.includes('miner') ? 'uk-active' : ''}">
<Link to={routes.miner}>{$_('nav.miner')}</Link>
</li> -->
<li class="uk-padding {$location_store.pathname.includes('transfer') ? 'uk-active' : ''}">
<Link to={routes.transfer}>{$_('nav.transactions')}</Link>
<Link to={watchOnly ? routes.wallet : routes.transfer}>{$_('nav.transactions')}</Link>
</li>
<!-- Remove Events tab till we get a fullnode set able to respond to these queries -->
<!-- <li><Link to={routes.events}>{$_("nav.events")}</Link></li> -->
<!-- Postpone MakeWhole release -->
<!--<li><MakeWholeLink /></li>-->
</ul>
</div>
{/if}
<!-- {#if $isInit} -->
<div class="uk-navbar-right">
<ul class="uk-navbar-nav">
<li>
<AccountSwitcher />
</li>
</ul>
</div>
<!-- {/if} -->
</nav>
</main>
2 changes: 0 additions & 2 deletions src/components/wallet/AccountNote.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
export let signingAccount
$signingAccount.note && console.log('>>> signingAccount.note', $signingAccount.note)
async function updateNote() {
associateNoteWithAccount($signingAccount.account, $signingAccount.note)
}
Expand Down
7 changes: 5 additions & 2 deletions src/components/wallet/AccountSwitcher.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { _ } from 'svelte-i18n'
import { Link } from 'svelte-navigator'
import { Link, navigate } from 'svelte-navigator'
import { signingAccount, allAccounts } from '../../modules/accounts'
import { setAccount } from '../../modules/accountActions'
Expand Down Expand Up @@ -34,13 +34,16 @@
{#if !$allAccounts}
<p>loading...</p>
{:else}
{#each $allAccounts as acc}
{#each $allAccounts.slice().sort((a, b) => a.nickname.localeCompare(b.nickname)) as acc}
<li>
<a
href={'#'}
class={$signingAccount.account == acc.account ? 'uk-text-primary' : ''}
on:click={() => {
if ($signingAccount.account != acc.account) {
if (acc.watch_only) {
navigate('wallet')
}
setAccount(acc.account)
}
}}
Expand Down
4 changes: 3 additions & 1 deletion src/components/wallet/AccountsList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@
</table>
{/if}
<div style="display: {showOptions ? 'block' : 'none'};">
<Actions {signingAccount} />
{#if $signingAccount}
<Actions {signingAccount} />
{/if}
</div>
</main>

Expand Down
19 changes: 2 additions & 17 deletions src/modules/accountActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,11 @@ export function findOneAccount(account: string): CarpeProfile | undefined {
export const setAccount = async (account: string, notifySucess = true) => {
if (get(signingAccount).account == account) return

const watchList = get(watchAccounts)
invoke('switch_profile', { account })
.then((res: CarpeProfile) => {
res.account = res.account.toLocaleUpperCase()
res.watch_only = watchList.includes(res.account.toLocaleLowerCase())
signingAccount.set(res)
isInit.set(true)
if (notifySucess) {
Expand Down Expand Up @@ -312,23 +314,6 @@ export const ignoreMigrate = () => {
.then(isLegacy) // reset if we actually did migrate the files
.catch((e: CarpeError) => raise_error(e, true, 'ignore_migrate'))
}
/*
export let invoke_makewhole = async (account: String): Promise<number> => {
// let demo_account = "613b6d9599f72134a4fa20bba4c75c36";
// account = demo_account;
console.log(">>> calling make whole");
return await invoke("query_makewhole", { account })
.then((a) => {
if (a.length > 0) {
console.log("MakeWhole " + account + ", coins: " + a[0].coins.value)
console.log(a)
}
console.log(a);
return a[0].coins.value
})
}
*/

export const updateMakeWhole = () => {
const mk = get(makeWhole)
Expand Down

0 comments on commit 01ef99e

Please sign in to comment.