Skip to content

Commit

Permalink
version up
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisDemyanko committed Nov 2, 2020
1 parent 67d7ec8 commit 99454e8
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 65 deletions.
8 changes: 4 additions & 4 deletions BeamWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = (
Expand Down
1 change: 1 addition & 0 deletions BeamWallet/BeamSDK/AppModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<BMTransaction*>*_Nullable transactions;
Expand Down
31 changes: 20 additions & 11 deletions BeamWallet/BeamSDK/AppModel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand All @@ -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;
Expand All @@ -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]);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions BeamWallet/BeamSDK/Objects/BMTransaction.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#import "BMAddress.h"
#import "AppModel.h"


@implementation BMTransaction

- (void)encodeWithCoder:(NSCoder *)encoder
Expand Down Expand Up @@ -648,5 +649,6 @@ -(NSString*)textDetails {
return [details componentsJoinedByString:@"\n\n"];
}


@end

23 changes: 18 additions & 5 deletions BeamWallet/BeamSDK/WalletModel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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<TxKernel::Ptr> 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;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
22 changes: 13 additions & 9 deletions BeamWallet/Model/Transaction/SendTransactionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -92,7 +92,7 @@ class SendTransactionViewModel: NSObject, WalletModelDelegate {
}
}
}
}
// }
}

public var requestedMaxPrivacy = false
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -110,7 +115,12 @@ class OpenWalletProgressViewController: BaseViewController {
}
}

private func openMainPage() {
@objc private func openMainPage() {
if isPresented {
return
}


isPresented = true

if phrase != nil {
Expand Down Expand Up @@ -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()
}
}
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
//
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand All @@ -264,6 +260,7 @@ extension TrustedNodeViewController: WalletModelDelegate {
@objc private func timerAction() {

let connected = AppModel.sharedManager().isConnected
isConnected = connected

if connected {
errorLabel.isHidden = true
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 99454e8

Please sign in to comment.