mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-10-05 19:28:26 +00:00
Prevent keysetId collision - more fixes
This commit is contained in:
+13
-9
@@ -99,10 +99,7 @@ export const MintModel = types
|
||||
})
|
||||
.actions(withSetPropAction) // TODO? start to use across app to avoid pure setter methods, e.g. mint.setProp('color', '#ccc')
|
||||
.views(self => ({
|
||||
getAllMintsKeysetIds(): string[] {
|
||||
const mintsStore = getRootStore(self).mintsStore
|
||||
return mintsStore.allKeysetIds
|
||||
}
|
||||
|
||||
}))
|
||||
.actions(self => ({
|
||||
addKeyset(keyset: CashuMintKeyset) {
|
||||
@@ -203,7 +200,7 @@ export const MintModel = types
|
||||
},
|
||||
keysetExists(keyset: CashuMintKeyset): boolean {
|
||||
return self.keysets.some(k => k.id === keyset.id)
|
||||
},
|
||||
}
|
||||
}))
|
||||
.actions(self => ({
|
||||
createProofsCounter(keyset: CashuMintKeyset) {
|
||||
@@ -224,7 +221,7 @@ export const MintModel = types
|
||||
}
|
||||
}))
|
||||
.actions(self => ({
|
||||
initKeyset(keyset: CashuMintKeyset) {
|
||||
initKeyset(keyset: CashuMintKeyset, allKeysetIds: string[]) {
|
||||
// Do not add unit the wallet does not have configured
|
||||
try {
|
||||
if(!self.isUnitSupported(keyset.unit as MintUnit)) {
|
||||
@@ -250,7 +247,7 @@ export const MintModel = types
|
||||
}
|
||||
|
||||
// Prevent keysetId collision with other mints
|
||||
if(CashuUtils.isCollidingKeysetId(keyset.id, self.getAllMintsKeysetIds())) {
|
||||
if(CashuUtils.isCollidingKeysetId(keyset.id, allKeysetIds)) {
|
||||
throw new AppError(
|
||||
Err.VALIDATION_ERROR,
|
||||
`KeysetId validation failed, collision detected for ${keyset.id}`,
|
||||
@@ -300,10 +297,15 @@ export const MintModel = types
|
||||
},
|
||||
}))
|
||||
.actions(self => ({
|
||||
refreshKeysets(freshKeysets: CashuMintKeyset[]) {
|
||||
refreshKeysets(freshKeysets: CashuMintKeyset[]) {
|
||||
const mintsStore = getRootStore(self).mintsStore
|
||||
const allKeysetIds = mintsStore.allKeysetIds
|
||||
|
||||
log.trace('[refreshKeysets]', {freshKeysets, allKeysetIds})
|
||||
|
||||
// add new keyset if not exists
|
||||
for (const keyset of freshKeysets) {
|
||||
self.initKeyset(keyset)
|
||||
self.initKeyset(keyset, allKeysetIds)
|
||||
self.setIsActive(keyset)
|
||||
}
|
||||
},
|
||||
@@ -335,6 +337,8 @@ export const MintModel = types
|
||||
if(self.validateURL(url)) {
|
||||
const mintsStore = getRootStore(self).mintsStore
|
||||
|
||||
//log.trace('[setMintUrl]', {mintsStore})
|
||||
|
||||
if(!mintsStore.alreadyExists(url)) {
|
||||
|
||||
const proofsStore = getRootStore(self).proofsStore
|
||||
|
||||
@@ -56,6 +56,9 @@ export const MintsStoreModel = types
|
||||
const mint = self.mints.find(m => m.mintUrl === mintUrl)
|
||||
return mint ? mint : undefined
|
||||
},
|
||||
get allKeysetIds() {
|
||||
return self.mints.flatMap(m => m.keysetIds)
|
||||
},
|
||||
}))
|
||||
.actions(withSetPropAction)
|
||||
.actions(self => ({
|
||||
@@ -144,7 +147,7 @@ export const MintsStoreModel = types
|
||||
continue
|
||||
}
|
||||
|
||||
mintInstance.initKeyset(keyset)
|
||||
mintInstance.initKeyset(keyset, self.allKeysetIds)
|
||||
}
|
||||
|
||||
for(const key of keys) {
|
||||
@@ -196,7 +199,7 @@ export const MintsStoreModel = types
|
||||
continue
|
||||
}
|
||||
|
||||
mintInstance.initKeyset(keyset)
|
||||
mintInstance.initKeyset(keyset, self.allKeysetIds)
|
||||
}
|
||||
|
||||
for(const key of keys) {
|
||||
@@ -287,9 +290,6 @@ export const MintsStoreModel = types
|
||||
|
||||
return Object.values(groupedByUnit) as MintsByUnit[]
|
||||
},
|
||||
get allKeysetIds() {
|
||||
return self.mints.flatMap(m => m.keysetIds)
|
||||
},
|
||||
alreadyExists(mintUrl: string) {
|
||||
return self.mints.some(m => m.mintUrl === mintUrl) ? true : false
|
||||
},
|
||||
|
||||
@@ -166,7 +166,7 @@ export const MintsScreen = observer(function MintsScreen({ route }: Props) {
|
||||
const matchingKeyset = keysets.find(keyset => selectedMint.keysets?.some(k => k.id === keyset.id))
|
||||
|
||||
if(!matchingKeyset) {
|
||||
throw new AppError(Err.VALIDATION_ERROR, 'No keyset match, provided URL likely points to different mint.')
|
||||
throw new AppError(Err.VALIDATION_ERROR, 'No keyset match, provided URL likely points to a different mint.')
|
||||
}
|
||||
|
||||
selectedMint.setMintUrl!(mintUrl)
|
||||
|
||||
Reference in New Issue
Block a user