Fix: migration to fix DAI token wrongly marked as decimals=0 when it's tagged as ERC721

pull/1442/head
Hwee-Boon Yar 5 years ago
parent c3a7276492
commit 767b57c912
  1. 13
      AlphaWallet/Core/Initializers/MigrationInitializer.swift

@ -15,7 +15,7 @@ class MigrationInitializer: Initializer {
}
func perform() {
config.schemaVersion = 4
config.schemaVersion = 5
config.migrationBlock = { migration, oldSchemaVersion in
if oldSchemaVersion < 2 {
//Fix bug created during multi-chain implementation. Where TokenObject instances are created from transfer Transaction instances, with the primaryKey as a empty string; so instead of updating an existing TokenObject, a duplicate TokenObject instead was created but with primaryKey empty
@ -49,5 +49,16 @@ class MigrationInitializer: Initializer {
}
}
}
config.migrationBlock = { migration, oldSchemaVersion in
if oldSchemaVersion < 5 {
migration.enumerateObjects(ofType: TokenObject.className()) { oldObject, newObject in
guard let oldObject = oldObject else { return }
guard let newObject = newObject else { return }
//Fix bug introduced when OpenSea suddenly includes the DAI stablecoin token in their results with an existing versioned API endpoint, and we wrongly tagged it as ERC721 with decimals=0. The earlier migration (version=4) only set the type back to ERC20, but the decimals remained as 0
guard let contract = oldObject["contract"] as? String, contract == "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359" else { return }
newObject["decimals"] = 18
}
}
}
}
}

Loading…
Cancel
Save