Skip to content

Commit

Permalink
Create add coinImage migrations field for enabledWallet using model f…
Browse files Browse the repository at this point in the history
…or v_40
  • Loading branch information
ant013 committed Dec 10, 2024
1 parent f52e37d commit 56e0606
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
6 changes: 6 additions & 0 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,8 @@
6B29072A2AF0CB8A006157D6 /* EventHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B29071E2AF0CB8A006157D6 /* EventHandler.swift */; };
6B55E33B2AF26D6400616B60 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = 6B55E33A2AF26D6400616B60 /* Starscream */; };
6B55E33D2AF26D7A00616B60 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = 6B55E33C2AF26D7A00616B60 /* Starscream */; };
6B5F33892D07FDF3001E23A4 /* EnabledWallet_v_0_40.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5F33882D07FDF3001E23A4 /* EnabledWallet_v_0_40.swift */; };
6B5F338A2D07FDF3001E23A4 /* EnabledWallet_v_0_40.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5F33882D07FDF3001E23A4 /* EnabledWallet_v_0_40.swift */; };
6B5F5E0E2C0C65F700E03EB2 /* MarketPlatformViewNew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5F5E0D2C0C65F700E03EB2 /* MarketPlatformViewNew.swift */; };
6B5F5E0F2C0C65F700E03EB2 /* MarketPlatformViewNew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5F5E0D2C0C65F700E03EB2 /* MarketPlatformViewNew.swift */; };
6B5F5E112C0C660900E03EB2 /* MarketPlatformViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5F5E102C0C660900E03EB2 /* MarketPlatformViewModel.swift */; };
Expand Down Expand Up @@ -4124,6 +4126,7 @@
6B29071B2AF0CB8A006157D6 /* WalletConnectAppShowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletConnectAppShowView.swift; sourceTree = "<group>"; };
6B29071D2AF0CB8A006157D6 /* WidgetCoinAppShowModule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WidgetCoinAppShowModule.swift; sourceTree = "<group>"; };
6B29071E2AF0CB8A006157D6 /* EventHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventHandler.swift; sourceTree = "<group>"; };
6B5F33882D07FDF3001E23A4 /* EnabledWallet_v_0_40.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnabledWallet_v_0_40.swift; sourceTree = "<group>"; };
6B5F5E0D2C0C65F700E03EB2 /* MarketPlatformViewNew.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketPlatformViewNew.swift; sourceTree = "<group>"; };
6B5F5E102C0C660900E03EB2 /* MarketPlatformViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketPlatformViewModel.swift; sourceTree = "<group>"; };
6B5F5E142C0DDD7100E03EB2 /* RankView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RankView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5085,6 +5088,7 @@
11B356A734526DECD9606A66 /* AccountRecord_v_0_36.swift */,
11B35E255F6CA21FFA9E6B42 /* FavoriteCoinRecord_v_0_38.swift */,
D3A87D5B2C8EFB1A00F6F619 /* EvmAccountRestoreState.swift */,
6B5F33882D07FDF3001E23A4 /* EnabledWallet_v_0_40.swift */,
);
path = Deprecated;
sourceTree = "<group>";
Expand Down Expand Up @@ -9509,6 +9513,7 @@
58AAAA71882CB345D56BBA00 /* CoinChartFactory.swift in Sources */,
11B351856787DD75A41861B6 /* CoinInvestorsViewModel.swift in Sources */,
11B3507F17791BC895872490 /* BrandFooterView.swift in Sources */,
6B5F338A2D07FDF3001E23A4 /* EnabledWallet_v_0_40.swift in Sources */,
D08D16852C2165490086E5A5 /* TonSendHandler.swift in Sources */,
6BCD53152A161F4800993F20 /* BackupViewModel.swift in Sources */,
11B35D10A6A15EFA47FCE6D0 /* TextCell.swift in Sources */,
Expand Down Expand Up @@ -10974,6 +10979,7 @@
D3833AFF2BF335D100ACECFB /* MarketNewsViewModel.swift in Sources */,
D36DE0D8272FD887000BC916 /* OneInchDataSource.swift in Sources */,
58AAA2EBAFC1C443C48BA857 /* CoinChartFactory.swift in Sources */,
6B5F33892D07FDF3001E23A4 /* EnabledWallet_v_0_40.swift in Sources */,
D08D16842C2165490086E5A5 /* TonSendHandler.swift in Sources */,
11B35085F61E874613B2B882 /* CoinInvestorsViewModel.swift in Sources */,
6BCD53142A161F4800993F20 /* BackupViewModel.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,32 +724,34 @@ enum StorageMigrator {
t.primaryKey([EnabledWalletCache_v_0_36.Columns.tokenQueryId.name, EnabledWalletCache_v_0_36.Columns.accountId.name], onConflict: .replace)
}

var enabledWallets: [EnabledWallet] = []
var enabledWallets: [EnabledWallet_v_0_40] = []
let rows = try Row.fetchCursor(db, sql: "SELECT * FROM \(EnabledWallet_v_0_34.databaseTableName)")

while let row = try rows.next() {
guard let tokenQueryId = tokenQueryId(tokenQueryId: row["tokenQueryId"], coinSettingsId: row["coinSettingsId"]) else {
continue
}

let updatedWallet = EnabledWallet(
let updatedWallet = EnabledWallet_v_0_40(
tokenQueryId: tokenQueryId,
accountId: row["accountId"], coinName: row["coinName"],
coinCode: row["coinCode"], tokenDecimals: row["tokenDecimals"]
accountId: row["accountId"],
coinName: row["coinName"],
coinCode: row["coinCode"],
tokenDecimals: row["tokenDecimals"]
)

enabledWallets.append(updatedWallet)
}

try db.drop(table: EnabledWallet_v_0_34.databaseTableName)
try db.create(table: EnabledWallet.databaseTableName) { t in
t.column(EnabledWallet.Columns.tokenQueryId.name, .text).notNull()
t.column(EnabledWallet.Columns.accountId.name, .text).notNull()
t.column(EnabledWallet.Columns.coinName.name, .text)
t.column(EnabledWallet.Columns.coinCode.name, .text)
t.column(EnabledWallet.Columns.tokenDecimals.name, .integer)

t.primaryKey([EnabledWallet.Columns.tokenQueryId.name, EnabledWallet.Columns.accountId.name], onConflict: .replace)
try db.create(table: EnabledWallet_v_0_40.databaseTableName) { t in
t.column(EnabledWallet_v_0_40.Columns.tokenQueryId.name, .text).notNull()
t.column(EnabledWallet_v_0_40.Columns.accountId.name, .text).notNull()
t.column(EnabledWallet_v_0_40.Columns.coinName.name, .text)
t.column(EnabledWallet_v_0_40.Columns.coinCode.name, .text)
t.column(EnabledWallet_v_0_40.Columns.tokenDecimals.name, .integer)

t.primaryKey([EnabledWallet_v_0_40.Columns.tokenQueryId.name, EnabledWallet_v_0_40.Columns.accountId.name], onConflict: .replace)
}

for wallet in enabledWallets {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import GRDB
import MarketKit

class EnabledWallet_v_0_40: Record {
let tokenQueryId: String
let accountId: String

let coinName: String?
let coinCode: String?
let tokenDecimals: Int?

init(tokenQueryId: String, accountId: String, coinName: String? = nil, coinCode: String? = nil, tokenDecimals: Int? = nil) {
self.tokenQueryId = tokenQueryId
self.accountId = accountId
self.coinName = coinName
self.coinCode = coinCode
self.tokenDecimals = tokenDecimals

super.init()
}

override class var databaseTableName: String {
"enabled_wallets"
}

enum Columns: String, ColumnExpression {
case tokenQueryId, accountId, coinName, coinCode, tokenDecimals
}

required init(row: Row) throws {
tokenQueryId = row[Columns.tokenQueryId]
accountId = row[Columns.accountId]
coinName = row[Columns.coinName]
coinCode = row[Columns.coinCode]
tokenDecimals = row[Columns.tokenDecimals]

try super.init(row: row)
}

override func encode(to container: inout PersistenceContainer) {
container[Columns.tokenQueryId] = tokenQueryId
container[Columns.accountId] = accountId
container[Columns.coinName] = coinName
container[Columns.coinCode] = coinCode
container[Columns.tokenDecimals] = tokenDecimals
}
}

0 comments on commit 56e0606

Please sign in to comment.