From fa490fd242775eaf5123b52dbcef1c771e636992 Mon Sep 17 00:00:00 2001
From: Prochmi99 <152851523+MiroslavProchazka@users.noreply.github.com>
Date: Fri, 3 Jan 2025 16:47:06 +0100
Subject: [PATCH] chore(suite-native): add migration for suite-native

---
 .../storage/src/migrations/discovery/v3.ts    | 10 +++++++
 .../src/migrations/wallet/accounts/v3.ts      | 11 ++++++++
 .../src/migrations/wallet/transactions/v3.ts  | 26 +++++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 suite-native/storage/src/migrations/discovery/v3.ts
 create mode 100644 suite-native/storage/src/migrations/wallet/accounts/v3.ts
 create mode 100644 suite-native/storage/src/migrations/wallet/transactions/v3.ts

diff --git a/suite-native/storage/src/migrations/discovery/v3.ts b/suite-native/storage/src/migrations/discovery/v3.ts
new file mode 100644
index 00000000000..09926650cc1
--- /dev/null
+++ b/suite-native/storage/src/migrations/discovery/v3.ts
@@ -0,0 +1,10 @@
+import { NetworkSymbol } from '@suite-common/wallet-config';
+// @ts-expect-error
+const deprecatedNetworks: NetworkSymbol[] = ['dash', 'btg', 'nmc', 'vtc', 'dgb'];
+
+export const migrateDiscoveryDeprecateNetworks = (
+    oldEnabledDiscoveryNetworkSymbols: NetworkSymbol[],
+): NetworkSymbol[] =>
+    oldEnabledDiscoveryNetworkSymbols.filter(
+        networkSymbol => !deprecatedNetworks.includes(networkSymbol),
+    );
diff --git a/suite-native/storage/src/migrations/wallet/accounts/v3.ts b/suite-native/storage/src/migrations/wallet/accounts/v3.ts
new file mode 100644
index 00000000000..17793e2667a
--- /dev/null
+++ b/suite-native/storage/src/migrations/wallet/accounts/v3.ts
@@ -0,0 +1,11 @@
+type Account = {
+    symbol: string;
+    key: string;
+};
+
+const deprecatedNetworks: string[] = ['dash', 'btg', 'nmc', 'vtc', 'dgb'];
+
+export const migrateAccountsDeprecateNetworks = (
+    oldAccounts: Account[] | undefined,
+): Account[] | undefined =>
+    oldAccounts?.filter(account => !deprecatedNetworks.includes(account.symbol));
diff --git a/suite-native/storage/src/migrations/wallet/transactions/v3.ts b/suite-native/storage/src/migrations/wallet/transactions/v3.ts
new file mode 100644
index 00000000000..1be4ec49104
--- /dev/null
+++ b/suite-native/storage/src/migrations/wallet/transactions/v3.ts
@@ -0,0 +1,26 @@
+type TransactionStub = {
+    symbol: string;
+};
+
+type AccountTransactionsType = {
+    [x: string]: TransactionStub[];
+};
+
+const deprecatedNetworks: string[] = ['dash', 'btg', 'nmc', 'vtc', 'dgb'];
+
+export const migrateTransactionsDeprecateNetworks = (
+    oldTransactions: AccountTransactionsType | undefined,
+): AccountTransactionsType | undefined => {
+    const newTransactions: AccountTransactionsType = {};
+
+    for (const oldKey in oldTransactions) {
+        const oldTxns = oldTransactions[oldKey];
+
+        const newTxns = oldTxns.filter(txn => !deprecatedNetworks.includes(txn.symbol));
+        if (newTxns.length > 0) {
+            newTransactions[oldKey] = newTxns;
+        }
+    }
+
+    return newTransactions;
+};