mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-10-06 11:48:24 +00:00
commit9163bd479aAuthor: minibits-cash <support@minibits.cash> Date: Fri Dec 8 22:04:52 2023 +0100 Improve lnurl address handling commita8a7840f70Author: minibits-cash <support@minibits.cash> Date: Fri Dec 8 22:00:11 2023 +0100 Improve lnurl address handling commit7f32a15e57Author: minibits-cash <support@minibits.cash> Date: Thu Dec 7 21:48:22 2023 +0100 Beta.4 release for alpha testers commit1c44c15ccdAuthor: minibits-cash <support@minibits.cash> Date: Thu Dec 7 19:37:54 2023 +0100 Upgrade deps commit2c9ab1b71cAuthor: minibits-cash <support@minibits.cash> Date: Thu Dec 7 11:13:43 2023 +0100 Reset cached mints on seed creation commit5fd9e95d2aAuthor: minibits-cash <support@minibits.cash> Date: Wed Dec 6 00:59:09 2023 +0100 Patch cashu-ts error handling commit436c670e7eAuthor: minibits-cash <support@minibits.cash> Date: Wed Dec 6 00:52:09 2023 +0100 Clean unused deps commitf6174bc607Author: minibits-cash <support@minibits.cash> Date: Wed Dec 6 00:51:45 2023 +0100 Remove debug commit868506a14cAuthor: minibits-cash <support@minibits.cash> Date: Wed Dec 6 00:50:33 2023 +0100 Improve receive error handling commite1bf087565Author: minibits-cash <support@minibits.cash> Date: Tue Dec 5 23:06:36 2023 +0100 Final small UX tuning commit875218d648Author: minibits-cash <support@minibits.cash> Date: Tue Dec 5 16:14:34 2023 +0100 Fix QR code error message commitc37b3e5ffeAuthor: minibits-cash <support@minibits.cash> Date: Tue Dec 5 12:53:23 2023 +0100 New beta release v0.1.5 - Off-device seed backup commit95811817faAuthor: minibits-cash <support@minibits.cash> Date: Tue Dec 5 09:35:21 2023 +0100 Align cashu-ts patch commitf61ad99e64Author: minibits-cash <support@minibits.cash> Date: Mon Dec 4 18:46:41 2023 +0100 Recovery - final tweaks commit6fa384c8efAuthor: minibits-cash <support@minibits.cash> Date: Mon Dec 4 00:10:32 2023 +0100 Fix counters in restore. commit50e9887405Author: minibits-cash <support@minibits.cash> Date: Sat Dec 2 23:53:37 2023 +0100 Seed recovery for testing commit00605c49afAuthor: minibits-cash <support@minibits.cash> Date: Tue Nov 28 00:57:08 2023 +0100 SeedRecovery before first tests commitaaefbe0e63Author: minibits-cash <support@minibits.cash> Date: Thu Nov 23 11:46:08 2023 +0100 Recovery screen - wip commitc019f63f48Author: minibits-cash <support@minibits.cash> Date: Mon Nov 20 00:44:35 2023 +0100 Remote backup screen with seed phrase commitada2f36070Author: minibits-cash <support@minibits.cash> Date: Sun Nov 19 22:03:06 2023 +0100 Generate seed
121 lines
3.8 KiB
TypeScript
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> {}
|