Skip to content

Commit 3fee94b

Browse files
authored
Merge pull request #754 from synonymdev/refactor/move-backup-verified-to-backup-repo
refactor: move backupVerified logic to BackupRepo
2 parents 2ca605b + 60d83c8 commit 3fee94b

4 files changed

Lines changed: 6 additions & 15 deletions

File tree

app/src/main/java/to/bitkit/repositories/BackupRepo.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ class BackupRepo @Inject constructor(
546546
}
547547

548548
Logger.info("Full restore success", context = TAG)
549+
}.onSuccess {
550+
settingsStore.update { it.copy(backupVerified = true) }
549551
}.onFailure { e ->
550552
Logger.warn("Full restore error", e = e, context = TAG)
551553
}

app/src/main/java/to/bitkit/repositories/WalletRepo.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,6 @@ class WalletRepo @Inject constructor(
300300
keychain.saveString(Keychain.Key.BIP39_PASSPHRASE.name, bip39Passphrase)
301301
}
302302
setWalletExistsState()
303-
}.onSuccess {
304-
settingsStore.update { it.copy(backupVerified = true) }
305303
}.onFailure {
306304
Logger.error("restoreWallet error", it, context = TAG)
307305
}

app/src/main/java/to/bitkit/services/MigrationService.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import kotlinx.coroutines.flow.first
2323
import kotlinx.coroutines.flow.update
2424
import kotlinx.serialization.SerialName
2525
import kotlinx.serialization.Serializable
26-
import kotlinx.serialization.encodeToString
2726
import kotlinx.serialization.json.JsonObject
2827
import kotlinx.serialization.json.JsonPrimitive
2928
import kotlinx.serialization.json.buildJsonObject
@@ -1212,6 +1211,8 @@ class MigrationService @Inject constructor(
12121211
val bitkitFiles = rnBackupClient.listFiles(fileGroup = "bitkit")?.list ?: emptyList()
12131212
retrieveAndApplyBitkitBackups(bitkitFiles)
12141213
markMigrationCompleted()
1214+
}.onSuccess {
1215+
settingsStore.update { it.copy(backupVerified = true) }
12151216
}.onFailure { e ->
12161217
Logger.error("RN remote backup restore failed", e, context = TAG)
12171218
throw e
@@ -1419,6 +1420,7 @@ class MigrationService @Inject constructor(
14191420
Logger.warn("Paid order $orderId not found in fetched orders", context = TAG)
14201421
null
14211422
}
1423+
14221424
order.state2 == com.synonym.bitkitcore.BtOrderState2.EXECUTED -> null
14231425
else -> TransferEntity(
14241426
id = txId,

app/src/test/java/to/bitkit/repositories/WalletRepoTest.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,13 @@ class WalletRepoTest : BaseUnitTest() {
167167
}
168168

169169
@Test
170-
fun `restoreWallet should set backupVerified to true on success`() = test {
170+
fun `restoreWallet should not call settingsStore`() = test {
171171
val mnemonic = "restore mnemonic"
172172
whenever(keychain.saveString(any(), any())).thenReturn(Unit)
173173

174174
val result = sut.restoreWallet(mnemonic, null)
175175

176176
assertTrue(result.isSuccess)
177-
verify(settingsStore).update(any())
178-
}
179-
180-
@Test
181-
fun `restoreWallet should not set backupVerified when keychain fails`() = test {
182-
val mnemonic = "restore mnemonic"
183-
whenever(keychain.saveString(any(), any())).thenThrow(error)
184-
185-
val result = sut.restoreWallet(mnemonic, null)
186-
187-
assertTrue(result.isFailure)
188177
verify(settingsStore, never()).update(any())
189178
}
190179

0 commit comments

Comments
 (0)