Files
minibits_wallet/src/models/Mint.ts
T
minibits-cash 64fee85221 Implement seed recovery:
commit 9163bd479a
Author: minibits-cash <support@minibits.cash>
Date:   Fri Dec 8 22:04:52 2023 +0100

    Improve lnurl address handling

commit a8a7840f70
Author: minibits-cash <support@minibits.cash>
Date:   Fri Dec 8 22:00:11 2023 +0100

    Improve lnurl address handling

commit 7f32a15e57
Author: minibits-cash <support@minibits.cash>
Date:   Thu Dec 7 21:48:22 2023 +0100

    Beta.4 release for alpha testers

commit 1c44c15ccd
Author: minibits-cash <support@minibits.cash>
Date:   Thu Dec 7 19:37:54 2023 +0100

    Upgrade deps

commit 2c9ab1b71c
Author: minibits-cash <support@minibits.cash>
Date:   Thu Dec 7 11:13:43 2023 +0100

    Reset cached mints on seed creation

commit 5fd9e95d2a
Author: minibits-cash <support@minibits.cash>
Date:   Wed Dec 6 00:59:09 2023 +0100

    Patch cashu-ts error handling

commit 436c670e7e
Author: minibits-cash <support@minibits.cash>
Date:   Wed Dec 6 00:52:09 2023 +0100

    Clean unused deps

commit f6174bc607
Author: minibits-cash <support@minibits.cash>
Date:   Wed Dec 6 00:51:45 2023 +0100

    Remove debug

commit 868506a14c
Author: minibits-cash <support@minibits.cash>
Date:   Wed Dec 6 00:50:33 2023 +0100

    Improve receive error handling

commit e1bf087565
Author: minibits-cash <support@minibits.cash>
Date:   Tue Dec 5 23:06:36 2023 +0100

    Final small UX tuning

commit 875218d648
Author: minibits-cash <support@minibits.cash>
Date:   Tue Dec 5 16:14:34 2023 +0100

    Fix QR code error message

commit c37b3e5ffe
Author: minibits-cash <support@minibits.cash>
Date:   Tue Dec 5 12:53:23 2023 +0100

    New beta release v0.1.5 - Off-device seed backup

commit 95811817fa
Author: minibits-cash <support@minibits.cash>
Date:   Tue Dec 5 09:35:21 2023 +0100

    Align cashu-ts patch

commit f61ad99e64
Author: minibits-cash <support@minibits.cash>
Date:   Mon Dec 4 18:46:41 2023 +0100

    Recovery - final tweaks

commit 6fa384c8ef
Author: minibits-cash <support@minibits.cash>
Date:   Mon Dec 4 00:10:32 2023 +0100

    Fix counters in restore.

commit 50e9887405
Author: minibits-cash <support@minibits.cash>
Date:   Sat Dec 2 23:53:37 2023 +0100

    Seed recovery for testing

commit 00605c49af
Author: minibits-cash <support@minibits.cash>
Date:   Tue Nov 28 00:57:08 2023 +0100

    SeedRecovery before first tests

commit aaefbe0e63
Author: minibits-cash <support@minibits.cash>
Date:   Thu Nov 23 11:46:08 2023 +0100

    Recovery screen - wip

commit c019f63f48
Author: minibits-cash <support@minibits.cash>
Date:   Mon Nov 20 00:44:35 2023 +0100

    Remote backup screen with seed phrase

commit ada2f36070
Author: minibits-cash <support@minibits.cash>
Date:   Sun Nov 19 22:03:06 2023 +0100

    Generate seed
2023-12-10 21:48:04 +01:00

121 lines
3.8 KiB
TypeScript

import {cast, Instance, SnapshotIn, SnapshotOut, types} from 'mobx-state-tree'
import {withSetPropAction} from './helpers/withSetPropAction'
import type {MintKeys} from '@cashu/cashu-ts/dist/lib/es5/model/types'
import {colors, getRandomIconColor} from '../theme'
import { log } from '../services'
import { deriveKeysetId } from '@cashu/cashu-ts'
// used as a helper type across app
export type MintBalance = {
mint: string
balance: number
}
export enum MintStatus {
ONLINE = 'ONLINE',
OFFLINE = 'OFFLINE'
}
export type MintProofsCounter = {
keyset: string
counter: number
}
/**
* This represents a Cashu mint
*/
export const MintModel = types
.model('Mint', {
mintUrl: types.identifier,
hostname: types.maybe(types.string),
shortname: types.maybe(types.string),
keys: types.frozen<MintKeys>(),
keysets: types.frozen<string[]>(),
proofsCounters: types.array(
types.model('MintProofsCounter', {
keyset: types.string,
counter: types.number,
})
),
color: types.optional(types.string, colors.palette.iconBlue200),
status: types.optional(types.frozen<MintStatus>(), MintStatus.ONLINE),
createdAt: types.optional(types.Date, new Date()),
})
.actions(withSetPropAction)
.views(self => ({
get currentProofsCounter() {
const currentKeyset = deriveKeysetId(self.keys)
return self.proofsCounters.find(c => c.keyset === currentKeyset)
},
}))
.actions(self => ({
validateURL(url: string) {
try {
new URL(url)
return true
} catch (e) {
return false
}
},
setHostname() {
try {
self.hostname = new URL(self.mintUrl).hostname
} catch (e) {
return false
}
},
setShortname(shortname: string) {
try {
self.shortname = shortname.slice(0, 25)
} catch (e) {
return false
}
},
setRandomColor() {
self.color = getRandomIconColor()
},
setColor(color: string) {
self.color = color
},
setStatus(status: MintStatus) {
self.status = status
},
updateKeys(keyset: string, keys: MintKeys) {
self.keysets.push(keyset)
self.keys = keys
self.keysets = cast(self.keysets)
},
increaseProofsCounter(numberOfProofs: number) {
const currentCounter = self.currentProofsCounter
if (currentCounter) {
log.trace('[increaseProofsCounter]', 'Before update', {currentCounter})
currentCounter.counter += numberOfProofs
log.trace('[increaseProofsCounter]', 'Updated proofsCounter', {numberOfProofs, currentCounter})
} else {
// If the counter doesn't exist, create a new one
const currentKeyset = deriveKeysetId(self.keys)
const newCounter = {
keyset: currentKeyset,
counter: numberOfProofs,
}
self.proofsCounters.push(newCounter)
log.trace('[increaseProofsCounter]', 'Adding new proofsCounter', {newCounter})
}
// Make sure to cast the frozen array back to a mutable array
self.proofsCounters = cast(self.proofsCounters)
},
}))
export type Mint = {
mintUrl: string
keys: MintKeys
keysets: string[]
} & Partial<Instance<typeof MintModel>>
export interface MintSnapshotOut extends SnapshotOut<typeof MintModel> {}
export interface MintSnapshotIn extends SnapshotIn<typeof MintModel> {}