diff --git a/BeamWallet.xcodeproj/project.pbxproj b/BeamWallet.xcodeproj/project.pbxproj index 714706ce..0969c638 100644 --- a/BeamWallet.xcodeproj/project.pbxproj +++ b/BeamWallet.xcodeproj/project.pbxproj @@ -4418,7 +4418,7 @@ CLANG_WARN_ENUM_CONVERSION = NO; CODE_SIGN_ENTITLEMENTS = Resources/BeamWallet.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 5; + CURRENT_PROJECT_VERSION = 17; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = KNU2R94BJK; ENABLE_BITCODE = NO; @@ -4493,7 +4493,7 @@ CLANG_WARN_ENUM_CONVERSION = NO; CODE_SIGN_ENTITLEMENTS = Resources/BeamWallet.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 5; + CURRENT_PROJECT_VERSION = 17; DEVELOPMENT_TEAM = KNU2R94BJK; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( @@ -4731,7 +4731,7 @@ CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletMasterNet.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 55; + CURRENT_PROJECT_VERSION = 56; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = KNU2R94BJK; ENABLE_BITCODE = NO; @@ -4808,7 +4808,7 @@ CODE_SIGN_ENTITLEMENTS = Resources/BeamWalletMasterNet.entitlements; CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 55; + CURRENT_PROJECT_VERSION = 56; DEVELOPMENT_TEAM = KNU2R94BJK; ENABLE_BITCODE = NO; FRAMEWORK_SEARCH_PATHS = ( diff --git a/BeamWallet/BeamSDK/AppModel.h b/BeamWallet/BeamSDK/AppModel.h index 78bd8830..8cd6090b 100644 --- a/BeamWallet/BeamSDK/AppModel.h +++ b/BeamWallet/BeamSDK/AppModel.h @@ -93,6 +93,7 @@ typedef void(^FeecalculatedBlock)(uint64_t fee, double change, uint64_t shielded @property (nonatomic,assign) BOOL isNodeChanging; @property (nonatomic,assign) BOOL isOwnNode; @property (nonatomic,assign) BMRestoreType restoreType; +@property (nonatomic,assign) BOOL isMaxPrivacyRequest; @property (nonatomic,strong) BMWalletStatus* _Nullable walletStatus; @property (nonatomic,strong) NSMutableArray*_Nullable transactions; diff --git a/BeamWallet/BeamSDK/AppModel.mm b/BeamWallet/BeamSDK/AppModel.mm index d0c43a19..983d3eb0 100644 --- a/BeamWallet/BeamSDK/AppModel.mm +++ b/BeamWallet/BeamSDK/AppModel.mm @@ -214,15 +214,16 @@ +(NSString*_Nonnull)chooseRandomNodeWithoutNodes:(NSArray*)nodes { for (const auto& item : peers) { BOOL found = NO; NSString *address = [NSString stringWithUTF8String:item.c_str()]; - - for (NSString *node in nodes) { - if([address isEqualToString:node]) { - found = YES; + if ([address rangeOfString:@"shanghai"].location == NSNotFound) { + for (NSString *node in nodes) { + if([address isEqualToString:node]) { + found = YES; + } + } + + if (!found) { + [array addObject:address]; } - } - - if (!found) { - [array addObject:address]; } } @@ -241,7 +242,9 @@ +(NSArray*_Nonnull)randomNodes { for (const auto& item : peers) { NSString *address = [NSString stringWithUTF8String:item.c_str()]; - [array addObject:address]; + if([address rangeOfString:@"shanghai"].location == NSNotFound) { + [array addObject:address]; + } } return array; @@ -254,7 +257,9 @@ +(NSString*_Nonnull)chooseRandomNode { for (const auto& item : peers) { NSString *address = [NSString stringWithUTF8String:item.c_str()]; - [array addObject:address]; + if([address rangeOfString:@"shanghai"].location == NSNotFound) { + [array addObject:address]; + } } srand([[NSDate date] timeIntervalSince1970]); @@ -1883,16 +1888,20 @@ -(NSString*_Nullable)feeError:(double)fee { -(void)calculateFee:(double)amount fee:(double)fee isShielded:(BOOL) isShielded result:(FeecalculatedBlock _Nonnull )block { + self.isMaxPrivacyRequest = isShielded; + self.feecalculatedBlock = block; Amount bAmount = round(amount * Rules::Coin); Amount bFee = fee; - wallet->getAsync()->calcShieldedCoinSelectionInfo(bAmount, bFee, isShielded); + wallet->getAsync()->calcShieldedCoinSelectionInfo(bAmount + bFee, 0, isShielded); } -(void)calculateFee2:(double)amount fee:(double)fee isShielded:(BOOL) isShielded result:(FeecalculatedBlock _Nonnull )block { + self.isMaxPrivacyRequest = isShielded; + self.feecalculatedBlock = block; Amount bAmount = round(amount * Rules::Coin); diff --git a/BeamWallet/BeamSDK/Objects/BMTransaction.m b/BeamWallet/BeamSDK/Objects/BMTransaction.m index d8f49302..0ff3ca78 100644 --- a/BeamWallet/BeamSDK/Objects/BMTransaction.m +++ b/BeamWallet/BeamSDK/Objects/BMTransaction.m @@ -24,6 +24,7 @@ #import "BMAddress.h" #import "AppModel.h" + @implementation BMTransaction - (void)encodeWithCoder:(NSCoder *)encoder @@ -648,5 +649,6 @@ -(NSString*)textDetails { return [details componentsJoinedByString:@"\n\n"]; } + @end diff --git a/BeamWallet/BeamSDK/WalletModel.mm b/BeamWallet/BeamSDK/WalletModel.mm index 4a28bdbc..de528d29 100644 --- a/BeamWallet/BeamSDK/WalletModel.mm +++ b/BeamWallet/BeamSDK/WalletModel.mm @@ -101,6 +101,17 @@ auto kernelId = to_hex(item.m_kernelID.m_pData, item.m_kernelID.nBytes); std::string comment(item.m_message.begin(), item.m_message.end()); + Amount fee = item.m_fee; + + std::vector shieldedInputs; + item.GetParameter(TxParameterID::InputsShielded, shieldedInputs); + if (shieldedInputs.size()) + { + Transaction::FeeSettings fs; + Amount shieldedFee = shieldedInputs.size() * (fs.m_Kernel + fs.m_ShieldedInput); + fee = shieldedFee + item.m_fee; + } + BMTransaction *transaction = [BMTransaction new]; transaction.realAmount = double(int64_t(item.m_amount)) / Rules::Coin; transaction.createdTime = item.m_createTime; @@ -117,8 +128,8 @@ transaction.identity = [NSString stringWithUTF8String:item.getIdentity(item.m_sender).c_str()]; transaction.ID = [NSString stringWithUTF8String:txIDToString(item.m_txId).c_str()]; transaction.isSelf = item.m_selfTx; - transaction.fee = double(int64_t(item.m_fee)) / Rules::Coin; - transaction.realFee = int64_t(item.m_fee); + transaction.fee = double(int64_t(fee)) / Rules::Coin; + transaction.realFee = int64_t(fee); transaction.kernelId = [NSString stringWithUTF8String:kernelId.c_str()]; transaction.canCancel = item.canCancel(); transaction.canResume = item.canResume(); @@ -1104,11 +1115,13 @@ { auto result = selectionRes.minimalFee; auto change = selectionRes.change; + if ([AppModel sharedManager].isMaxPrivacyRequest) { + change = selectionRes.change + selectionRes.shieldedInputsFee; + } + + auto shieldedInputsFee = selectionRes.shieldedInputsFee; -// if (change > 0) { -// change = change + selectionRes.selectedFee; //+ selectionRes.requestedFee; -// } double amount = double(int64_t(change)) / Rules::Coin; [AppModel sharedManager].feecalculatedBlock(result, amount, shieldedInputsFee); diff --git a/BeamWallet/Model/Transaction/SendTransactionViewModel.swift b/BeamWallet/Model/Transaction/SendTransactionViewModel.swift index 8d871e6d..b7489e5d 100644 --- a/BeamWallet/Model/Transaction/SendTransactionViewModel.swift +++ b/BeamWallet/Model/Transaction/SendTransactionViewModel.swift @@ -75,8 +75,8 @@ class SendTransactionViewModel: NSObject, WalletModelDelegate { } public func calculateFee() { - if AppModel.sharedManager().walletStatus?.shielded ?? 0 > 0 { - AppModel.sharedManager().calculateFee(Double(amount) ?? 0, fee: 0, isShielded: maxPrivacy) { (result, changed, shieldedInputsFee) in + // if AppModel.sharedManager().walletStatus?.shielded ?? 0 > 0 { + AppModel.sharedManager().calculateFee(Double(amount) ?? 0, fee: (Double(fee) ?? 0), isShielded: maxPrivacy) { (result, changed, shieldedInputsFee) in DispatchQueue.main.async { self.shieldedInputsFee = shieldedInputsFee let current = UInt64(self.fee) ?? 0 @@ -92,7 +92,7 @@ class SendTransactionViewModel: NSObject, WalletModelDelegate { } } } - } + // } } public var requestedMaxPrivacy = false @@ -507,15 +507,19 @@ class SendTransactionViewModel: NSObject, WalletModelDelegate { } public func calculateChange() { - if (AppModel.sharedManager().walletStatus?.shielded ?? 0) > 0 { +// AppModel.sharedManager().calculateFee2((Double(amount) ?? 0), fee: (Double(fee) ?? 0), isShielded: maxPrivacy || requestedMaxPrivacy) { (fee, change, shieldedInputsFee) in +// self.onCalculateChanged?(change) +// } + + // if (AppModel.sharedManager().walletStatus?.shielded ?? 0) > 0 { AppModel.sharedManager().calculateFee2((Double(amount) ?? 0), fee: (Double(fee) ?? 0), isShielded: maxPrivacy || requestedMaxPrivacy) { (fee, change, shieldedInputsFee) in self.onCalculateChanged?(change) } - } - else { - AppModel.sharedManager().calculateChange(Double(amount) ?? 0, fee: Double(fee) ?? 0) - } - +// } +// else { +// AppModel.sharedManager().calculateChange(Double(amount) ?? 0, fee: Double(fee) ?? 0) +// } +// if AppModel.sharedManager().isToken(toAddress) { _ = AppModel.sharedManager().getTransactionParameters(toAddress) } diff --git a/BeamWallet/ViewControllers/Login/OpenWalletProgressViewController.swift b/BeamWallet/ViewControllers/Login/OpenWalletProgressViewController.swift index 827c3d62..af9c8336 100644 --- a/BeamWallet/ViewControllers/Login/OpenWalletProgressViewController.swift +++ b/BeamWallet/ViewControllers/Login/OpenWalletProgressViewController.swift @@ -80,11 +80,16 @@ class OpenWalletProgressViewController: BaseViewController { cancelButton.isHidden = false } else if phrase == nil { + timeoutTimer?.invalidate() timeoutTimer = Timer.scheduledTimer(timeInterval: 10.0, target: self, selector: #selector(onTimeOut), userInfo: nil, repeats: false) progressTitleLabel.text = Localizable.shared.strings.loading_wallet cancelButton.isHidden = true } + else if phrase != nil { + timeoutTimer?.invalidate() + timeoutTimer = Timer.scheduledTimer(timeInterval: 10.0, target: self, selector: #selector(openMainPage), userInfo: nil, repeats: false) + } if let base = self.navigationController as? BaseNavigationController { base.enableSwipeToDismiss = false @@ -110,7 +115,12 @@ class OpenWalletProgressViewController: BaseViewController { } } - private func openMainPage() { + @objc private func openMainPage() { + if isPresented { + return + } + + isPresented = true if phrase != nil { @@ -306,11 +316,7 @@ class OpenWalletProgressViewController: BaseViewController { @objc private func onTimeOut() { if Settings.sharedManager().isChangedNode() { - if !self.isPresented { - self.isPresented = true - - self.openMainPage() - } + self.openMainPage() } } } @@ -321,8 +327,7 @@ extension OpenWalletProgressViewController : WalletModelDelegate { DispatchQueue.main.async { [weak self] in guard let strongSelf = self else { return } - if connected && !strongSelf.isPresented && !AppModel.sharedManager().isRestoreFlow { - strongSelf.isPresented = true + if connected && !AppModel.sharedManager().isRestoreFlow { strongSelf.progressView.progress = 1 DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { @@ -416,16 +421,11 @@ extension OpenWalletProgressViewController : WalletModelDelegate { let error = _error as NSError if error.code == 2 && Settings.sharedManager().isChangedNode() { - if !strongSelf.isPresented { - strongSelf.isPresented = true - strongSelf.openMainPage() - } + strongSelf.openMainPage() } else if error.code == 1 { - if !strongSelf.isPresented { - strongSelf.isPresented = true - strongSelf.openMainPage() - } + strongSelf.openMainPage() + // if strongSelf.navigationController?.viewControllers.last is OpenWalletProgressViewController { // strongSelf.confirmAlert(title: Localizable.shared.strings.incompatible_node_title, message: Localizable.shared.strings.incompatible_node_info, cancelTitle: Localizable.shared.strings.cancel, confirmTitle: Localizable.shared.strings.change_settings, cancelHandler: { (_ ) in // @@ -438,10 +438,7 @@ extension OpenWalletProgressViewController : WalletModelDelegate { // } } else if error.code == 4 { - if !strongSelf.isPresented { - strongSelf.isPresented = true - strongSelf.openMainPage() - } + strongSelf.openMainPage() } else if !strongSelf.isPresented { if let controllers = strongSelf.navigationController?.viewControllers { diff --git a/BeamWallet/ViewControllers/Main/Settings/TrustedNodeViewController.swift b/BeamWallet/ViewControllers/Main/Settings/TrustedNodeViewController.swift index f6144b99..68cec3c1 100644 --- a/BeamWallet/ViewControllers/Main/Settings/TrustedNodeViewController.swift +++ b/BeamWallet/ViewControllers/Main/Settings/TrustedNodeViewController.swift @@ -31,7 +31,8 @@ class TrustedNodeViewController: BMInputViewController { private var timer = Timer() private var timeoutTimer = Timer() private var event: EventType! - + private var isConnected = false + private var oldAddress: String! init(event: EventType) { @@ -238,22 +239,17 @@ extension TrustedNodeViewController: UITextFieldDelegate { extension TrustedNodeViewController: WalletModelDelegate { func onWalletStatusChange(_ status: BMWalletStatus) { - if status.available > 0 { + if status.available > 0 && event == .restore && !Settings.sharedManager().connectToRandomNode { DispatchQueue.main.async { [weak self] in guard let strongSelf = self else { return } - if !strongSelf.isPresented { - strongSelf.isPresented = true - strongSelf.timer.invalidate() - SVProgressHUD.dismiss() - strongSelf.openMainPage() - } + strongSelf.timeout() } } } @objc private func timeout() { SVProgressHUD.dismiss() - if !isPresented { + if !isPresented && !Settings.sharedManager().connectToRandomNode { isPresented = true timer.invalidate() timeoutTimer.invalidate() @@ -264,6 +260,7 @@ extension TrustedNodeViewController: WalletModelDelegate { @objc private func timerAction() { let connected = AppModel.sharedManager().isConnected + isConnected = connected if connected { errorLabel.isHidden = true @@ -275,6 +272,7 @@ extension TrustedNodeViewController: WalletModelDelegate { } timer.invalidate() + timeoutTimer.invalidate() timeoutTimer = Timer.scheduledTimer(timeInterval: 15, target: self, selector: #selector(timeout), userInfo: nil, repeats: false) } else { diff --git a/BeamWallet/ViewControllers/Main/Wallet/Send/SendConfirmViewController.swift b/BeamWallet/ViewControllers/Main/Wallet/Send/SendConfirmViewController.swift index c03945fd..889ff299 100644 --- a/BeamWallet/ViewControllers/Main/Wallet/Send/SendConfirmViewController.swift +++ b/BeamWallet/ViewControllers/Main/Wallet/Send/SendConfirmViewController.swift @@ -215,13 +215,13 @@ extension SendConfirmViewController: WalletModelDelegate { func onChangeCalculated(_ amount: Double) { DispatchQueue.main.async { - let am = amount -// let total = AppModel.sharedManager().realTotal(Double(self.viewModel.amount) ?? 0, fee: Double(self.viewModel.fee) ?? 0) -// let left = (AppModel.sharedManager().walletStatus?.realAmount ?? 0) - total -// -// if left < am { -// am = 0 -// } + var am = amount + let total = AppModel.sharedManager().realTotal(Double(self.viewModel.amount) ?? 0, fee: Double(self.viewModel.fee) ?? 0) + let left = (AppModel.sharedManager().walletStatus?.realAmount ?? 0) - total + + if left < am { + am = 0 + } let totalString = String.currency(value: am) //+ Localizable.shared.strings.beam let item = BMMultiLineItem(title: Localizable.shared.strings.change_locked, detail: totalString, detailFont: SemiboldFont(size: 16), detailColor: UIColor.white)