From 5afc3cee2231280b13bfb3c72e26cf57317527ed Mon Sep 17 00:00:00 2001
From: feruz <fmiboy@gmail.com>
Date: Fri, 6 Dec 2019 20:16:05 +0200
Subject: [PATCH] balances corrected on transfer screens

---
 src/containers/steemWalletContainer.js        | 26 +++++------
 src/containers/transferContainer.js           | 45 +++++++++----------
 src/screens/transfer/screen/transferScreen.js | 13 +++++-
 3 files changed, 43 insertions(+), 41 deletions(-)

diff --git a/src/containers/steemWalletContainer.js b/src/containers/steemWalletContainer.js
index 76050f1d1..da1375319 100644
--- a/src/containers/steemWalletContainer.js
+++ b/src/containers/steemWalletContainer.js
@@ -201,21 +201,17 @@ const WalletContainer = ({
   const _navigate = async (transferType, fundType) => {
     let balance;
 
-    switch (fundType) {
-      case 'STEEM':
-        balance = Math.round(walletData.balance * 1000) / 1000;
-        break;
-      case 'SBD':
-        balance = Math.round(walletData.sbdBalance * 1000) / 1000;
-        break;
-      case 'SAVING_STEEM':
-        balance = Math.round(walletData.savingBalance * 1000) / 1000;
-        break;
-      case 'SAVING_SBD':
-        balance = Math.round(walletData.savingBalanceSbd * 1000) / 1000;
-        break;
-      default:
-        break;
+    if (transferType === 'transfer_token' && fundType === 'STEEM') {
+      balance = Math.round(walletData.balance * 1000) / 1000;
+    }
+    if (transferType === 'transfer_token' && fundType === 'SBD') {
+      balance = Math.round(walletData.sbdBalance * 1000) / 1000;
+    }
+    if (transferType === 'withdraw_steem' && fundType === 'STEEM') {
+      balance = Math.round(walletData.savingBalance * 1000) / 1000;
+    }
+    if (transferType === 'withdraw_sbd' && fundType === 'SBD') {
+      balance = Math.round(walletData.savingBalanceSbd * 1000) / 1000;
     }
 
     if (isPinCodeOpen) {
diff --git a/src/containers/transferContainer.js b/src/containers/transferContainer.js
index 8a3823620..9830c0a44 100644
--- a/src/containers/transferContainer.js
+++ b/src/containers/transferContainer.js
@@ -34,6 +34,8 @@ class TransferContainer extends Component {
     super(props);
     this.state = {
       fundType: props.navigation.getParam('fundType', ''),
+      balance: props.navigation.getParam('balance', ''),
+      transferType: props.navigation.getParam('transferType', ''),
       selectedAccount: props.currentAccount,
     };
   }
@@ -63,33 +65,28 @@ class TransferContainer extends Component {
   };
 
   fetchBalance = username => {
-    const { fundType } = this.state;
+    const { fundType, transferType } = this.state;
 
     getAccount(username).then(async account => {
       let balance;
-      switch (fundType) {
-        case 'STEEM':
-          balance = account[0].balance.replace(fundType, '');
-          break;
-        case 'SBD':
-          balance = account[0].sbd_balance.replace(fundType, '');
-          break;
-        case 'ESTM':
-          this._getUserPointsBalance(username);
-          break;
-        case 'SAVING_STEEM':
-          this.setState({ fundType: 'STEEM' });
-          balance = account[0].savings_balance.replace(' STEEM', '');
-          break;
-        case 'SAVING_SBD':
-          this.setState({ fundType: 'STEEM DOLLAR' });
-          balance = account[0].savings_sbd_balance.replace(' SBD', '');
-          break;
-        case 'STEEM_POWER':
-          balance = account[0].balance.replace(fundType, '');
-          break;
-        default:
-          break;
+
+      if (transferType === 'transfer_token' && fundType === 'STEEM') {
+        balance = account[0].balance.replace(fundType, '');
+      }
+      if (transferType === 'transfer_token' && fundType === 'SBD') {
+        balance = account[0].sbd_balance.replace(fundType, '');
+      }
+      if (transferType === 'points' && fundType === 'ESTM') {
+        this._getUserPointsBalance(username);
+      }
+      if (transferType === 'transfer_to_saving' && fundType === 'STEEM') {
+        balance = account[0].balance.replace(fundType, '');
+      }
+      if (transferType === 'transfer_to_saving' && fundType === 'SBD') {
+        balance = account[0].sbd_balance.replace(fundType, '');
+      }
+      if (transferType === 'powerUp' && fundType === 'STEEM') {
+        balance = account[0].balance.replace(fundType, '');
       }
 
       const local = await getUserDataWithUsername(username);
diff --git a/src/screens/transfer/screen/transferScreen.js b/src/screens/transfer/screen/transferScreen.js
index efd2c9e82..f6405a8d3 100644
--- a/src/screens/transfer/screen/transferScreen.js
+++ b/src/screens/transfer/screen/transferScreen.js
@@ -31,10 +31,19 @@ class TransferView extends Component {
     super(props);
     this.state = {
       from: props.currentAccountName,
-      destination: props.transferType === 'powerUp' ? props.currentAccountName : '',
+      destination:
+        props.transferType === 'powerUp' ||
+        props.transferType === 'withdraw_steem' ||
+        props.transferType === 'withdraw_steem'
+          ? props.currentAccountName
+          : '',
       amount: '',
       memo: '',
-      isUsernameValid: !!(props.transferType === 'powerUp' && props.currentAccountName),
+      isUsernameValid: !!(
+        props.transferType === 'powerUp' ||
+        props.transferType === 'withdraw_steem' ||
+        (props.transferType === 'withdraw_steem' && props.currentAccountName)
+      ),
       steemConnectTransfer: false,
       isTransfering: false,
     };