Skip to content
This repository has been archived by the owner on Oct 8, 2019. It is now read-only.

feat(Segwit): handle v4 payload upgrade #1510

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/partials/upgradeV4.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.alert-in-app
uib-alert(type="danger", close="insist = false", ng-show="insist")
span(translate="NEED_SECOND_PASSWORD_FOR_UPGRADE")
.modal-header.flex-center.upgrade-header(data-preflight-tag="Upgrade")
h3(translate="Upgrade to V4")
.modal-body
span(translate="Upgrade for segwitP2SH support 🏄‍")
.modal-footer.pal.flex-end
button.button-primary(ui-ladda="busy", ng-click="upgradeV4()" ng-disabled="waiting", ladda-translate="CONTINUE", data-style="expand-left")
26 changes: 26 additions & 0 deletions assets/js/controllers/upgradeV4.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
angular
.module('walletApp')
.controller('UpgradeCtrlV4', UpgradeCtrlV4);

function UpgradeCtrlV4 ($scope, Wallet, $uibModalInstance, $log, $window, $translate, $timeout, $rootScope) {
$scope.waiting = true;
$scope.busy = false;

$scope.upgradeV4 = () => {
const secondPasswordCancelled = () => {
$scope.insist = true;
$scope.busy = false;
};

const success = () => {
$scope.busy = false;
$uibModalInstance.close();
};

$scope.insist = false;
$scope.busy = true;
Wallet.upgradeV4(success, secondPasswordCancelled);
};

$timeout(() => $scope.waiting = false, 3000);
}
10 changes: 10 additions & 0 deletions assets/js/controllers/wallet.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ function WalletCtrl ($scope, $rootScope, Wallet, $uibModal, $timeout, Alerts, $i

$scope.checkGoals = () => {
if ($scope.status.isLoggedIn) {
if (Wallet.goal.upgradeV4) {
$uibModal.open({
templateUrl: 'partials/upgradeV4.pug',
controller: 'UpgradeCtrlV4',
backdrop: 'static',
windowClass: 'bc-modal',
keyboard: false
});
Wallet.goal.upgradeV4 = void 0;
}
if (Wallet.goal.upgrade) {
$uibModal.open({
templateUrl: 'partials/upgrade.pug',
Expand Down
31 changes: 30 additions & 1 deletion assets/js/services/wallet.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ function Wallet ($http, $window, $timeout, $location, $injector, Alerts, MyWalle
const wallet = {
goal: {
auth: false,
upgrade: false
upgrade: false,
upgradeV4: false
},
status: {
isLoggedIn: false,
Expand Down Expand Up @@ -352,6 +353,31 @@ function Wallet ($http, $window, $timeout, $location, $injector, Alerts, MyWalle
.then(proceed).catch(cancelSecondPasswordCallback);
};

wallet.upgradeV4 = (successCallback, cancelSecondPasswordCallback) => {
let success = () => {
wallet.status.didUpgradeToV4 = true;
wallet.my.wallet.getHistory().then(() => {
wallet.status.didLoadBalances = true;
// Montitored by e.g. acticity feed:
wallet.status.didLoadTransactions = true;
});
successCallback();
AngularHelper.$safeApply();
};

let error = (e) => {
wallet.store.enableLogout();
wallet.store.setIsSynchronizedWithServer(true);
$window.location.reload();
};

let proceed = (password) => {
wallet.my.wallet.upgradeToV4(password, success, error);
};
wallet.askForSecondPasswordIfNeeded()
.then(proceed).catch(cancelSecondPasswordCallback);
};

wallet.legacyAddresses = () => (
wallet.status.isLoggedIn ? wallet.my.wallet.keys : []
);
Expand Down Expand Up @@ -855,6 +881,9 @@ function Wallet ($http, $window, $timeout, $location, $injector, Alerts, MyWalle
} else if (event === 'hd_wallets_does_not_exist') {
wallet.status.didUpgradeToHd = false;
wallet.goal.upgrade = true;
} else if (event === 'perform_v4_payload_upgrade') {
wallet.status.didUpgradeToV4 = false;
wallet.goal.upgradeV4 = true;
} else if (event === 'wallet not found') {
Alerts.displayError('WALLET_NOT_FOUND');
} else if (event === 'ticker_updated' || event === 'did_set_latest_block') {
Expand Down