Added $scope.fundsAreInsufficient for triggering UI.
This commit is contained in:
parent
3df2836081
commit
3cedfa5146
1 changed files with 46 additions and 6 deletions
|
|
@ -7,6 +7,8 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
var satToUnit;
|
var satToUnit;
|
||||||
var unitDecimals;
|
var unitDecimals;
|
||||||
var satToBtc;
|
var satToBtc;
|
||||||
|
var spendableAmountInSatoshis = null;
|
||||||
|
|
||||||
var SMALL_FONT_SIZE_LIMIT = 10;
|
var SMALL_FONT_SIZE_LIMIT = 10;
|
||||||
var LENGTH_EXPRESSION_LIMIT = 19;
|
var LENGTH_EXPRESSION_LIMIT = 19;
|
||||||
var LENGTH_BEFORE_COMMA_EXPRESSION_LIMIT = 8;
|
var LENGTH_BEFORE_COMMA_EXPRESSION_LIMIT = 8;
|
||||||
|
|
@ -22,6 +24,10 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
$scope.amountModel = { amount: 0 };
|
$scope.amountModel = { amount: 0 };
|
||||||
|
|
||||||
|
// Use insufficient for logic, as when the amount is invalid, funds being
|
||||||
|
// either sufficent or insufficient doesn't make sense.
|
||||||
|
$scope.fundsAreInsufficient = false;
|
||||||
|
|
||||||
$scope.isChromeApp = platformInfo.isChromeApp;
|
$scope.isChromeApp = platformInfo.isChromeApp;
|
||||||
$scope.isAndroid = platformInfo.isAndroid;
|
$scope.isAndroid = platformInfo.isAndroid;
|
||||||
$scope.isIos = platformInfo.isIOS;
|
$scope.isIos = platformInfo.isIOS;
|
||||||
|
|
@ -134,6 +140,12 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
});
|
});
|
||||||
|
|
||||||
altUnitIndex = 0;
|
altUnitIndex = 0;
|
||||||
|
|
||||||
|
if ($scope.fromWalletId) {
|
||||||
|
var fromWallet = profileService.getWallet($scope.fromWalletId);
|
||||||
|
console.log('got fromWallet.');
|
||||||
|
updateSpendableAmountInSatoshisFromWallet(fromWallet);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Go to...
|
// Go to...
|
||||||
|
|
@ -387,24 +399,41 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
|
|
||||||
var a = fromFiat(result);
|
var a = fromFiat(result);
|
||||||
if (a) {
|
if (a) {
|
||||||
$scope.alternativeAmount = txFormatService.formatAmount(a * unitToSatoshi, true);
|
var amountInSatoshis = a * unitToSatoshi;
|
||||||
$scope.allowSend = lodash.isNumber(a) && a > 0
|
$scope.fundsAreInsufficient = !!$scope.fromWalletId
|
||||||
|
&& spendableAmountInSatoshis !== null
|
||||||
|
&& spendableAmountInSatoshis < amountInSatoshis;
|
||||||
|
|
||||||
|
$scope.alternativeAmount = txFormatService.formatAmount(amountInSatoshis, true);
|
||||||
|
$scope.allowSend = lodash.isNumber(a)
|
||||||
|
&& a > 0
|
||||||
&& (!$scope.shapeshiftOrderId
|
&& (!$scope.shapeshiftOrderId
|
||||||
|| (a >= $scope.minShapeshiftAmount && a <= $scope.maxShapeshiftAmount));
|
|| (a >= $scope.minShapeshiftAmount && a <= $scope.maxShapeshiftAmount))
|
||||||
|
&& !$scope.fundsAreInsufficient;
|
||||||
} else {
|
} else {
|
||||||
if (result) {
|
if (result) {
|
||||||
$scope.alternativeAmount = 'N/A';
|
$scope.alternativeAmount = 'N/A';
|
||||||
} else {
|
} else {
|
||||||
$scope.alternativeAmount = null;
|
$scope.alternativeAmount = null;
|
||||||
}
|
}
|
||||||
|
$scope.fundsAreInsufficient = false;
|
||||||
$scope.allowSend = false;
|
$scope.allowSend = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$scope.fundsAreInsufficient = !!$scope.fromWalletId
|
||||||
|
&& spendableAmountInSatoshis !== null
|
||||||
|
&& spendableAmountInSatoshis < result * unitToSatoshi;
|
||||||
|
|
||||||
$scope.alternativeAmount = $filter('formatFiatAmount')(toFiat(result));
|
$scope.alternativeAmount = $filter('formatFiatAmount')(toFiat(result));
|
||||||
$scope.allowSend = lodash.isNumber(result) && result > 0
|
$scope.allowSend = lodash.isNumber(result)
|
||||||
|
&& result > 0
|
||||||
&& (!$scope.shapeshiftOrderId
|
&& (!$scope.shapeshiftOrderId
|
||||||
|| (result >= $scope.minShapeshiftAmount && result <= $scope.maxShapeshiftAmount));
|
|| (result >= $scope.minShapeshiftAmount && result <= $scope.maxShapeshiftAmount))
|
||||||
|
&& !$scope.fundsAreInsufficient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$scope.fundsAreInsufficient = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -584,6 +613,7 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
|
rateService.updateRates();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -632,5 +662,15 @@ angular.module('copayApp.controllers').controller('amountController', function($
|
||||||
updateUnitUI();
|
updateUnitUI();
|
||||||
$scope.close();
|
$scope.close();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function updateSpendableAmountInSatoshisFromWallet(wallet) {
|
||||||
|
if (wallet.status) {
|
||||||
|
spendableAmountInSatoshis = wallet.status.spendableAmount;
|
||||||
|
} else if (fromWallet.cachedStatus) {
|
||||||
|
spendableAmountInSatoshis = wallet.cachedStatus.spendableAmount;
|
||||||
|
} else {
|
||||||
|
spendableAmountInSatoshis = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue