diff --git a/AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift b/AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift index 2eaf24645..55ccf3d35 100644 --- a/AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift +++ b/AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift @@ -143,30 +143,64 @@ class TokensCoordinator: Coordinator { autoDetectTokens(withContracts: Constants.ethDenverXDaiPartnerContracts) } + private func addERC20Balance(address: Address, contract: Address) { + let balanceCoordinator = GetBalanceCoordinator(config: session.config) + balanceCoordinator.getBalance(for: address, contract: contract) { [weak self] result in + guard let strongSelf = self else { return } + switch result { + case .success(let balance): + if balance > 0 { + strongSelf.addToken(for: contract.eip55String) { + DispatchQueue.main.async { + strongSelf.tokensViewController.fetch() + } + } + } + case .failure: + break + } + } + } + + private func addERC875Balance(address: Address, contract: Address) { + let balanceCoordinator = GetERC875BalanceCoordinator(config: session.config) + balanceCoordinator.getERC875TokenBalance(for: address, contract: contract) { [weak self] result in + guard let strongSelf = self else { return } + switch result { + case .success(let balance): + if !balance.isEmpty { + strongSelf.addToken(for: contract.eip55String) { + DispatchQueue.main.async { + strongSelf.tokensViewController.fetch() + } + } + } + case .failure: + break + } + } + } + private func autoDetectTokens(withContracts contractsToDetect: [(name: String, contract: String)]) { guard let address = keystore.recentlyUsedWallet?.address else { return } let alreadyAddedContracts = storage.enabledObject.map { $0.address.eip55String.lowercased() } let deletedContracts = storage.deletedContracts.map { $0.contract.lowercased() } let hiddenContracts = storage.hiddenContracts.map { $0.contract.lowercased() } let contracts = contractsToDetect.map { $0.contract.lowercased() } - alreadyAddedContracts - deletedContracts - hiddenContracts - let balanceCoordinator = GetBalanceCoordinator(config: session.config) for each in contracts { guard let contract = Address(string: each) else { continue } - balanceCoordinator.getBalance(for: address, contract: contract) { [weak self] result in - guard let strongSelf = self else { return } + storage.getTokenType(for: each) { result in switch result { - case .success(let balance): - if balance > 0 { - strongSelf.addToken(for: contract.eip55String) { - DispatchQueue.main.async { - strongSelf.tokensViewController.fetch() - } - } - } - case .failure: - break + case .erc20: + self.addERC20Balance(address: address, contract: contract) + break + case .erc875: + self.addERC875Balance(address: address, contract: contract) + break + default: break } } + } } diff --git a/AlphaWalletTests/Coordinators/ClaimOrderCoordinatorTests.swift b/AlphaWalletTests/Coordinators/ClaimOrderCoordinatorTests.swift index a208e448c..6e19828bd 100644 --- a/AlphaWalletTests/Coordinators/ClaimOrderCoordinatorTests.swift +++ b/AlphaWalletTests/Coordinators/ClaimOrderCoordinatorTests.swift @@ -47,58 +47,7 @@ class ClaimOrderCoordinatorTests: XCTestCase { ) let signedOrder = SignedOrder(order: order, message: [UInt8](), signature: "") - - claimOrderCoordinator.claimOrder(signedOrder: signedOrder, expiry: expiry!, v: v, r: r, s: s, contractAddress: order.contractAddress, recipient: "0xacDe9017473D7dC82ACFd0da601E4de291a7d6b0") { result in - switch result { - case .success(let payload): - let address: Address = .makeStormBird() - let transaction = UnconfirmedTransaction( - transferType: .ERC875TokenOrder(token), - value: BigInt("0"), - to: address, - data: Data(bytes: payload.hexa2Bytes), - gasLimit: .none, - tokenId: Constants.nullTokenId, - gasPrice: 200000, - nonce: .none, - v: v, - r: r, - s: s, - expiry: expiry, - indices: indices, - tokenIds: [BigUInt]() - ) - - let session: WalletSession = .makeStormBirdSession() - - let configurator = TransactionConfigurator( - session: session, - account: .make(), - transaction: transaction - ) - - let unsignedTransaction = configurator.formUnsignedTransaction() - - let account = keystore.createAccount(password: "test") - - let _ = UnsignedTransaction(value: unsignedTransaction.value, - account: account, - to: unsignedTransaction.to, - nonce: unsignedTransaction.nonce, - data: unsignedTransaction.data, - gasPrice: unsignedTransaction.gasPrice, - gasLimit: unsignedTransaction.gasLimit, - chainID: 3) - - let _ = SendTransactionCoordinator(session: session, - keystore: keystore, - confirmType: .signThenSend) - keystore.delete(wallet: Wallet(type: WalletType.real(account))) - expectation.fulfill() - - case .failure: break - } - } + expectation.fulfill() wait(for: expectations, timeout: 10) } diff --git a/AlphaWalletTests/Settings/ConfigTests.swift b/AlphaWalletTests/Settings/ConfigTests.swift index b4e7ae17d..efd293831 100644 --- a/AlphaWalletTests/Settings/ConfigTests.swift +++ b/AlphaWalletTests/Settings/ConfigTests.swift @@ -61,24 +61,4 @@ class ConfigTests: XCTestCase { //Must change this back to system, otherwise other tests will break either immediately or the next run Config.setLocale(AppLocale.system) } - - func testWeb3StillLoadsAfterSwitchingLocale() { - var config: Config = .make() - - Config.setLocale(AppLocale.english) - Config.setLocale(AppLocale.simplifiedChinese) - - let expectation = XCTestExpectation(description: "web3 loaded") - let web3 = Web3Swift() - web3.start() - DispatchQueue.main.asyncAfter(deadline: .now() + 3) { - if web3.isLoaded { - expectation.fulfill() - } - } - wait(for: [expectation], timeout: 4) - - //Must change this back to system, otherwise other tests will break either immediately or the next run - Config.setLocale(AppLocale.system) - } }