Merge pull request #2094 from AlphaWallet/#2079

Lack confirmation message when a developer opened/imported a TSML file into αW #2079
pull/1999/head
Hwee-Boon Yar 4 years ago committed by GitHub
commit 6e09220cf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      AlphaWallet/AppCoordinator.swift
  2. 16
      AlphaWallet/InCoordinator.swift
  3. 1
      AlphaWallet/Localization/en.lproj/Localizable.strings
  4. 7
      AlphaWallet/Localization/es.lproj/Localizable.strings
  5. 1
      AlphaWallet/Localization/ja.lproj/Localizable.strings
  6. 1
      AlphaWallet/Localization/ko.lproj/Localizable.strings
  7. 7
      AlphaWallet/Localization/zh-Hans.lproj/Localizable.strings
  8. 31
      AlphaWallet/TokenScriptClient/Coordinators/AssetDefinitionStoreCoordinator.swift

@ -357,12 +357,17 @@ extension AppCoordinator: CustomUrlSchemeCoordinatorDelegate {
}
extension AppCoordinator: AssetDefinitionStoreCoordinatorDelegate {
func show(error: Error, for viewController: AssetDefinitionStoreCoordinator) {
inCoordinator?.show(error: error)
}
func addedTokenScript(forContract contract: AlphaWallet.Address, forServer server: RPCServer) {
func addedTokenScript(forContract contract: AlphaWallet.Address, forServer server: RPCServer, destinationFileInUse: Bool, filename: String) {
inCoordinator?.addImported(contract: contract, forServer: server)
if !destinationFileInUse {
inCoordinator?.show(openedURL: filename)
}
}
}

@ -641,6 +641,22 @@ class InCoordinator: NSObject, Coordinator {
}
}
func show(openedURL filename: String) {
let controller = UIAlertController(title: nil, message: "\(filename) file imported with no error", preferredStyle: .alert)
controller.popoverPresentationController?.sourceView = presentationViewController.view
controller.addAction(.init(title: R.string.localizable.oK(), style: .default))
presentationViewController.present(controller, animated: true)
}
private var presentationViewController: UIViewController {
if let controller = navigationController.presentedViewController {
return controller
} else {
return navigationController
}
}
func listOfBadTokenScriptFilesChanged(fileNames: [TokenScriptFileIndices.FileName]) {
tokensCoordinator?.listOfBadTokenScriptFilesChanged(fileNames: fileNames)
}

@ -409,6 +409,7 @@
"light" = "Light";
"qrCode.title" = "Point your camera on QR code";
"tokenScript.notSupportedSchema.error" = "Please upgrade AlphaWallet to support this TokenScript file";
"tokenScript.moveFile.error" = "Error moving asset definition file from %@ to: %@: %@";
"TokenScript.verifying" = "Verifying...";
"TokenScript.showErrors" = "Show errors";
"TokenScript.type1.supportedAndSigned" = "Verified";

@ -451,3 +451,10 @@
"wallet.security.level.orange" = "NO BLOQUEADO";
"wallet.security.level.green" = "100% SEGURO";
"wallets.showSeedPhrase.subtitle.error" = "No compartas tu copia de seguridad. Los miembros del equipo de AlphaWallet nunca te la pedirán.";
"token.transactionConfirmation.gas.title" = "Speed (Gas)";
"token.transactionConfirmation.contract.title" = "Contract";
"token.transactionConfirmation.default" = "Default";
"token.transactionConfirmation.title" = "Confirm Transfer?";
"a.wallet.token.transaction.inProgress.title" = "Transaction in Progress";
"a.wallet.token.transaction.inProgress.subtitle" = "The transaction is sent to the Ethereum\nblockchain. It might take few minutes\nto be confirmed by miners.";
"a.wallet.token.transaction.inProgress.confirm" = "OK, great!";

@ -409,6 +409,7 @@
"qrCode.title" = "Point your camera on QR code";
"a.claim.token.failed.serverDown" = "a.claim.token.failed.serverDown";
"tokenScript.notSupportedSchema.error" = "Please upgrade AlphaWallet to support this TokenScript file";
"tokenScript.moveFile.error" = "Error moving asset definition file from %@ to: %@: %@";
"TokenScript.verifying" = "Verifying...";
"TokenScript.showErrors" = "Show errors";
"TokenScript.type1.supportedAndSigned" = "Verified";

@ -408,6 +408,7 @@
"qrCode.title" = "Point your camera on QR code";
"a.claim.token.failed.serverDown" = "a.claim.token.failed.serverDown";
"tokenScript.notSupportedSchema.error" = "Please upgrade AlphaWallet to support this TokenScript file";
"tokenScript.moveFile.error" = "Error moving asset definition file from %@ to: %@: %@";
"TokenScript.verifying" = "Verifying...";
"TokenScript.showErrors" = "Show errors";
"TokenScript.type1.supportedAndSigned" = "Verified";

@ -451,3 +451,10 @@
"wallet.security.level.orange" = "未锁定";
"wallet.security.level.green" = "100% 安全";
"wallets.showSeedPhrase.subtitle.error" = "请勿将备份文件分享给他人。AlphaWallet 团队成员绝不会向您索要备份。";
"token.transactionConfirmation.gas.title" = "Speed (Gas)";
"token.transactionConfirmation.contract.title" = "Contract";
"token.transactionConfirmation.default" = "Default";
"token.transactionConfirmation.title" = "Confirm Transfer?";
"a.wallet.token.transaction.inProgress.title" = "Transaction in Progress";
"a.wallet.token.transaction.inProgress.subtitle" = "The transaction is sent to the Ethereum\nblockchain. It might take few minutes\nto be confirmed by miners.";
"a.wallet.token.transaction.inProgress.confirm" = "OK, great!";

@ -5,7 +5,7 @@ import UIKit
protocol AssetDefinitionStoreCoordinatorDelegate: class {
func show(error: Error, for viewController: AssetDefinitionStoreCoordinator)
func addedTokenScript(forContract contract: AlphaWallet.Address, forServer server: RPCServer)
func addedTokenScript(forContract contract: AlphaWallet.Address, forServer server: RPCServer, destinationFileInUse: Bool, filename: String)
}
struct SchemaCheckError: LocalizedError {
@ -15,6 +15,20 @@ struct SchemaCheckError: LocalizedError {
}
}
enum OpenURLError: Error {
case unsupportedTokenScriptVersion
case copyTokenScriptURL(_ url: URL, _ destinationURL: URL, error: Error)
var localizedDescription: String {
switch self {
case .unsupportedTokenScriptVersion:
return R.string.localizable.tokenScriptNotSupportedSchemaError()
case .copyTokenScriptURL(let url, let destinationFileName, let error):
return R.string.localizable.tokenScriptMoveFileError(url.path, destinationFileName.path, error.localizedDescription)
}
}
}
class AssetDefinitionStoreCoordinator: Coordinator {
private class WeakRef<T: AnyObject> {
weak var object: T?
@ -128,7 +142,8 @@ class AssetDefinitionStoreCoordinator: Coordinator {
isTokenScriptOrXml = true
case .unsupportedTokenScriptVersion:
try? FileManager.default.removeItem(at: url)
delegate?.show(error: SchemaCheckError(msg: R.string.localizable.tokenScriptNotSupportedSchemaError()), for: self)
delegate?.show(error: OpenURLError.unsupportedTokenScriptVersion, for: self)
return true
case .unknownXml:
try? FileManager.default.removeItem(at: url)
@ -139,6 +154,8 @@ class AssetDefinitionStoreCoordinator: Coordinator {
let filename = url.lastPathComponent
let destinationFileName = overridesDirectory.appendingPathComponent(filename)
let destinationFileInUse = overrides?.contains(destinationFileName) ?? false
do {
try? FileManager.default.removeItem(at: destinationFileName )
try FileManager.default.moveItem(at: url, to: destinationFileName )
@ -146,16 +163,18 @@ class AssetDefinitionStoreCoordinator: Coordinator {
if let contracts = XMLHandler.getHoldingContracts(forTokenScript: contents) {
for (contract, chainId) in contracts {
let server = RPCServer(chainID: chainId)
delegate?.addedTokenScript(forContract: contract, forServer: server)
delegate?.addedTokenScript(forContract: contract, forServer: server, destinationFileInUse: destinationFileInUse, filename: filename)
}
}
}
return true
}
} catch {
NSLog("Error moving asset definition file from \(url.path) to: \(destinationFileName.path): \(error)")
delegate?.show(error: OpenURLError.copyTokenScriptURL(url, destinationFileName, error: error), for: self)
}
return false
}
}
private func watchDirectoryContents(changeHandler: @escaping () -> Void) {
guard directoryWatcher == nil else { return }

Loading…
Cancel
Save