Skip to content

Commit

Permalink
Merge pull request #87 from gandlafbtc/dev/upgrade-cashu
Browse files Browse the repository at this point in the history
Dev/upgrade cashu
  • Loading branch information
gandlafbtc authored May 23, 2023
2 parents 05cdda1 + 0aa541e commit a0a075c
Show file tree
Hide file tree
Showing 32 changed files with 322 additions and 183 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ If you want to run your private instance of nutstash where tokens are synced wit
1. change `/tmp/nutstash/nutstash-data` in `docker-compose.yml` to your preferred location.
1. change the owner of the directory to `1000` ===> `sudo chown -R 1000:1000 [directory-path]`
1. start nutstash with: `docker-compose up --build -d`
1. activate the options to sync to server in nutstash settings
1. activate the options to sync to server in nutstash settings

## Contributing

Read [this guide](/docs/contribute.md) on how to contribute.
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ services:
- /tmp/nutstash/nutstash-data:/app/data

volumes:
nutstash-data:
nutstash-data:
82 changes: 63 additions & 19 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelte-cashu-wallet",
"version": "0.1.11",
"version": "0.1.12",
"private": true,
"scripts": {
"dev": "vite dev",
Expand All @@ -14,7 +14,7 @@
"format": "prettier --plugin-search-dir . --write ."
},
"devDependencies": {
"@cashu/cashu-ts": "0.7.0",
"@cashu/cashu-ts": "0.8.0-rc.3",
"@sveltejs/adapter-auto": "^1.0.1",
"@sveltejs/kit": "^1.0.0",
"@typescript-eslint/eslint-plugin": "^5.45.0",
Expand Down
39 changes: 39 additions & 0 deletions src/actions/walletActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { deriveKeysetId, type MintKeys } from '@cashu/cashu-ts';
import type { Mint } from '../model/mint';
import { mints } from '../stores/mints';
import { get } from 'svelte/store';
import { toast } from '../stores/toasts';

// export const send = async () => {

// }

// export const mint = async () => {

// }

// export const receive = async () => {

// }

// export const melt = async () => {

// }

export const updateMintKeys = (mint: Mint, newKeys: MintKeys) => {
const allMints = [...get(mints)];
const toBeUpdated = allMints.find((m) => mint.mintURL === m.mintURL);
if (!toBeUpdated) {
toast(
'error',
'the keys of this mint have changed, but could not be updated in the wallet',
'Error'
);
throw new Error('could not update mint keys');
}
toBeUpdated.keys = newKeys;
const newKeyset = deriveKeysetId(newKeys);
toBeUpdated.keysets = [newKeyset, ...toBeUpdated.keysets];
mints.set(allMints);
toast('info', 'the new keyset ID is: ' + newKeyset, 'The keys of this mint have rotated');
};
2 changes: 1 addition & 1 deletion src/comp/Setting.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<a href="/history" class="btn btn-outline">History</a>
</div>
{#if PUBLIC_SELFHOSTED}
<SelfhostedSetting></SelfhostedSetting>
<SelfhostedSetting />
{/if}

<div class="divider col-span-5">Cashu</div>
Expand Down
2 changes: 1 addition & 1 deletion src/comp/elements/CoinSelection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { Mint } from '../../model/mint';
import AvailableTokensTable from '../tokens/AvailableTokensTable.svelte';
import { getAmountForTokenSet } from '../util/walletUtils';
import type { Proof } from "@cashu/cashu-ts";
import type { Proof } from '@cashu/cashu-ts';
export let mint: Mint;
export let amount: number = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/comp/elements/ScanLN.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let qrScanner: Html5QrcodeScanner;
function onScanSuccess(decodedText:string, decodedResult: any) {
function onScanSuccess(decodedText: string, decodedResult: any) {
// handle the scanned code as you like, for example:
scannedlnInvoice = decodedText;
if (browser) {
Expand Down
2 changes: 1 addition & 1 deletion src/comp/elements/ScanNpub.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let qrScanner: Html5QrcodeScanner;
function onScanSuccess(decodedText: string, decodedResult:any) {
function onScanSuccess(decodedText: string, decodedResult: any) {
// handle the scanned code as you like, for example:
scannedNpub = decodedText;
if (browser) {
Expand Down
95 changes: 49 additions & 46 deletions src/comp/elements/SelfhostedSetting.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,60 @@
let isMintsChecked = false;
let isTokensChecked = false;
let isLoading = false
let isLoading = false;
const handleToggleSync = () => {
if (!$selfhostedSyncTokens) {
toast('info', 'Reload app to activate', 'Sync tokens to server');
}
};
const restoreFromServer= async () =>{
isLoading = true
try {
if (isMintsChecked) {
await restoreMints()
}
if (isTokensChecked) {
await restoreTokens()
}
toast('success', 'Successfully restored from server','Done!')
} catch (error) {
console.log(error)
toast('error', 'Error while restoring from server','Could not restore')
} finally {
isLoading = false
}
modalOpen = false
}
const restoreFromServer = async () => {
isLoading = true;
try {
if (isMintsChecked) {
await restoreMints();
}
if (isTokensChecked) {
await restoreTokens();
}
toast('success', 'Successfully restored from server', 'Done!');
} catch (error) {
console.log(error);
toast('error', 'Error while restoring from server', 'Could not restore');
} finally {
isLoading = false;
}
modalOpen = false;
};
const restoreMints =async () => {
const restoreMints = async () => {
try {
const data = await fetch("/api/backup/mints")
const mintsFromServer = await data.json()
const data = await fetch('/api/backup/mints');
const mintsFromServer = await data.json();
if (!mintsFromServer) {
toast('warning', 'no mints found on server','Mints not restored')
return
toast('warning', 'no mints found on server', 'Mints not restored');
return;
}
mints.set(mintsFromServer)
mints.set(mintsFromServer);
} catch (error) {
console.error(error)
toast('error', 'error while mints restoring from server','Server error')
console.error(error);
toast('error', 'error while mints restoring from server', 'Server error');
}
}
};
const restoreTokens =async () => {
const restoreTokens = async () => {
try {
const data = await fetch("/api/backup/tokens")
const tokensFromServer = await data.json()
const data = await fetch('/api/backup/tokens');
const tokensFromServer = await data.json();
if (!tokensFromServer) {
toast('warning', 'no tokens found on server','Tokens not restored')
return
toast('warning', 'no tokens found on server', 'Tokens not restored');
return;
}
token.set(tokensFromServer)
token.set(tokensFromServer);
} catch (error) {
console.error(error)
toast('error', 'error while tokens restoring from server','Server error')
console.error(error);
toast('error', 'error while tokens restoring from server', 'Server error');
}
}
};
</script>

<div class="divider col-span-5 font-bold">Selfhosted</div>
Expand All @@ -78,7 +75,7 @@
on:click={handleToggleSync}
/>
</div>
<div class="divider col-span-5"></div>
<div class="divider col-span-5" />

<div class="col-span-2">
<label for="">Restore from server</label>
Expand All @@ -93,11 +90,19 @@
<input type="checkbox" bind:checked={isTokensChecked} class="checkbox checkbox-primary" />
<span class="label-text">Tokens</span>
</label>
<label for="restore-from-server-modal" class="btn {isTokensChecked||isMintsChecked?'':'btn-disabled'}">Restore</label>
<label
for="restore-from-server-modal"
class="btn {isTokensChecked || isMintsChecked ? '' : 'btn-disabled'}">Restore</label
>
</div>
</div>

<input type="checkbox" id="restore-from-server-modal" class="modal-toggle" bind:checked={modalOpen}/>
<input
type="checkbox"
id="restore-from-server-modal"
class="modal-toggle"
bind:checked={modalOpen}
/>
<div class="modal">
<div class="modal-box">
<h3 class="font-bold text-lg">Restore from server</h3>
Expand All @@ -112,9 +117,7 @@
</ul>
<div class="modal-action">
<label for="restore-from-server-modal" class="btn btn-outline">close</label>
<button class="btn" on:click={restoreFromServer}>
restore
</button>
<button class="btn" on:click={restoreFromServer}> restore </button>
</div>
</div>
</div>
Loading

1 comment on commit a0a075c

@vercel
Copy link

@vercel vercel bot commented on a0a075c May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.