diff --git a/web/cashtab/src/components/Airdrop/__tests__/__snapshots__/Airdrop.test.js.snap b/web/cashtab/src/components/Airdrop/__tests__/__snapshots__/Airdrop.test.js.snap --- a/web/cashtab/src/components/Airdrop/__tests__/__snapshots__/Airdrop.test.js.snap +++ b/web/cashtab/src/components/Airdrop/__tests__/__snapshots__/Airdrop.test.js.snap @@ -3,15 +3,29 @@ exports[`Wallet with BCH balances 1`] = ` Array [
-

- MigrationTestAlpha -

+

+ MigrationTestAlpha +

+ + + edit.svg + + +
You currently have 0 XEC @@ -21,7 +35,7 @@
,
,
XEC Airdrop Calculator
@@ -103,15 +117,29 @@ exports[`Wallet with BCH balances and tokens 1`] = ` Array [
-

- MigrationTestAlpha -

+

+ MigrationTestAlpha +

+ + + edit.svg + + +
You currently have 0 XEC @@ -121,7 +149,7 @@
,
,
XEC Airdrop Calculator
@@ -203,15 +231,29 @@ exports[`Wallet with BCH balances and tokens and state field 1`] = ` Array [
-

- MigrationTestAlpha -

+

+ MigrationTestAlpha +

+ + + edit.svg + + +
0.06 @@ -220,7 +262,7 @@
,
,
XEC Airdrop Calculator
@@ -302,15 +344,29 @@ exports[`Wallet without BCH balance 1`] = ` Array [
-

- MigrationTestAlpha -

+

+ MigrationTestAlpha +

+ + + edit.svg + + +
You currently have 0 XEC @@ -320,7 +376,7 @@
,
,
XEC Airdrop Calculator
@@ -402,10 +458,24 @@ exports[`Without wallet defined 1`] = ` Array [
+
You currently have 0 XEC @@ -415,7 +485,7 @@
,
,
XEC Airdrop Calculator
diff --git a/web/cashtab/src/components/Common/CustomIcons.js b/web/cashtab/src/components/Common/CustomIcons.js --- a/web/cashtab/src/components/Common/CustomIcons.js +++ b/web/cashtab/src/components/Common/CustomIcons.js @@ -24,6 +24,7 @@ import { ReactComponent as Pdf } from 'assets/file-pdf.svg'; import { ReactComponent as Plus } from 'assets/plus.svg'; import { ReactComponent as Download } from 'assets/download.svg'; +import { ReactComponent as Edit } from 'assets/edit.svg'; export const CashLoadingIcon = ; export const CashReceivedNotificationIcon = () => ( @@ -109,6 +110,14 @@ width: 1.3em; `; +export const ThemedEditOutlined = styled(Edit)` + stroke: ${props => props.theme.eCashBlue}; + fill: ${props => props.theme.eCashBlue}; + min-width: 20px; + min-height: 20px; + cursor: pointer; +`; + export const LoadingBlock = styled.div` width: 100%; display: flex; diff --git a/web/cashtab/src/components/Common/WalletLabel.js b/web/cashtab/src/components/Common/WalletLabel.js --- a/web/cashtab/src/components/Common/WalletLabel.js +++ b/web/cashtab/src/components/Common/WalletLabel.js @@ -1,12 +1,21 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import styled from 'styled-components'; +import { ThemedEditOutlined } from 'components/Common/CustomIcons'; +import { Link } from 'react-router-dom'; + +const LabelCtn = styled.div` + display: flex; + align-items: center; + justify-content: center; + gap: 3%; +`; const WalletName = styled.h4` font-size: 16px; display: inline-block; color: ${props => props.theme.lightWhite}; - margin-bottom: 0px; + margin-bottom: 2px; @media (max-width: 400px) { font-size: 16px; } @@ -14,11 +23,21 @@ const WalletLabel = ({ name }) => { return ( - <> + {name && typeof name === 'string' && ( {name} )} - + + + + ); }; diff --git a/web/cashtab/src/components/Configure/Configure.js b/web/cashtab/src/components/Configure/Configure.js --- a/web/cashtab/src/components/Configure/Configure.js +++ b/web/cashtab/src/components/Configure/Configure.js @@ -369,6 +369,7 @@ margin-bottom: 6px; h3 { font-size: 16px; + flex: 1 1 0; display: inline-block; color: ${props => props.theme.darkBlue}; margin: 0; @@ -380,11 +381,15 @@ } h4 { font-size: 16px; + flex: 1 1 0; display: inline-block; color: ${props => props.theme.eCashBlue} !important; margin: 0; text-align: right; } + ${SWButtonCtn} { + flex: 1 1 0; + } @media (max-width: 500px) { flex-direction: column; margin-bottom: 12px; @@ -480,7 +485,8 @@ const { addNewSavedWallet, activateWallet, - renameWallet, + renameSavedWallet, + renameActiveWallet, deleteWallet, validateMnemonic, getSavedWallets, @@ -585,6 +591,15 @@ setShowTranslationWarning(true); } + if ( + location && + location.state && + location.state.showRenameWalletModal + ) { + setShowRenameWalletModal(true); + setWalletToBeRenamed(wallet); + } + // if this was routed from Home screen's Add to Contact link if (location && location.state && location.state.contactToAdd) { let tempContactListArray; @@ -757,6 +772,7 @@ }; const changeWalletName = async () => { + let oldActiveWalletName; if (!isValidNewWalletNameLength(newWalletName)) { setNewWalletNameIsValid(false); return; @@ -767,14 +783,29 @@ console.log( `Changing wallet ${walletToBeRenamed.name} name to ${newWalletName}`, ); - const renameSuccess = await renameWallet( - walletToBeRenamed.name, - newWalletName, - ); + let renameSuccess; + + if (walletToBeRenamed.name === wallet.name) { + oldActiveWalletName = walletToBeRenamed.name; + renameSuccess = await renameActiveWallet( + wallet, + walletToBeRenamed.name, + newWalletName, + ); + } else { + renameSuccess = await renameSavedWallet( + walletToBeRenamed.name, + newWalletName, + ); + } if (renameSuccess) { Modal.success({ - content: `Wallet "${walletToBeRenamed.name}" renamed to "${newWalletName}"`, + content: `Wallet "${ + oldActiveWalletName !== undefined + ? oldActiveWalletName + : walletToBeRenamed.name + }" renamed to "${newWalletName}"`, }); } else { Modal.error({ @@ -1486,7 +1517,7 @@ /> )} {wallet && wallet.mnemonic && ( - + @@ -1579,6 +1610,20 @@

Currently active

+ + + showPopulatedRenameWalletModal( + wallet, + ) + } + /> + + addSavedWalletToContact(wallet) + } + /> +
{savedWallets.map(sw => ( diff --git a/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap b/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap --- a/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap +++ b/web/cashtab/src/components/Configure/__tests__/__snapshots__/Configure.test.js.snap @@ -2,10 +2,10 @@ exports[`Wallet with BCH balances and tokens 1`] = `

,
,
@@ -248,13 +290,13 @@ onClick={[Function]} >
,
@@ -357,18 +413,18 @@ exports[`Without wallet defined 1`] = `
XEC
eToken @@ -126,7 +126,7 @@ exports[`Wallet with BCH balances and tokens 1`] = `

Receive @@ -155,7 +155,7 @@ } >
ecash: qzagy47m vh6qxkvcn3acjnz73rkhkc6y7c cxkrr6zd @@ -230,16 +230,16 @@

XEC
eToken @@ -250,7 +250,7 @@ exports[`Wallet with BCH balances and tokens and state field 1`] = `

Receive @@ -279,7 +279,7 @@ } >
ecash: qzagy47m vh6qxkvcn3acjnz73rkhkc6y7c cxkrr6zd @@ -354,16 +354,16 @@

XEC
eToken @@ -374,7 +374,7 @@ exports[`Wallet without BCH balance 1`] = `

Receive @@ -403,7 +403,7 @@ } >
ecash: qzagy47m vh6qxkvcn3acjnz73rkhkc6y7c cxkrr6zd @@ -478,16 +478,16 @@

XEC
,

0 XEC

= @@ -364,16 +378,16 @@ } >
Advanced
@@ -435,10 +449,10 @@
Sign Message
@@ -497,10 +511,10 @@
,

0 XEC

= @@ -926,16 +954,16 @@ } >
Advanced
@@ -997,10 +1025,10 @@
Sign Message
@@ -1059,10 +1087,10 @@
,

0 XEC

= @@ -1487,17 +1529,17 @@ } >
Advanced
@@ -1559,10 +1601,10 @@
Sign Message
@@ -1621,10 +1663,10 @@
,

0 XEC

= @@ -2050,16 +2106,16 @@ } >
Advanced
@@ -2121,10 +2177,10 @@
Sign Message
@@ -2183,10 +2239,10 @@
Verify Message
@@ -2251,10 +2307,24 @@ exports[`Without wallet defined 1`] = ` Array [
,

0 XEC

= @@ -2607,16 +2677,16 @@ } >
Advanced
@@ -2678,10 +2748,10 @@
Sign Message
@@ -2740,10 +2810,10 @@
Verify Message
diff --git a/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap b/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap --- a/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap +++ b/web/cashtab/src/components/Send/__tests__/__snapshots__/SendToken.test.js.snap @@ -4,10 +4,10 @@ exports[`Wallet with BCH balances and tokens and state field 1`] = `
6.001 @@ -33,7 +33,7 @@ } >
@@ -222,7 +222,7 @@ } >
@@ -135,7 +135,7 @@
@@ -173,7 +173,7 @@
@@ -211,7 +211,7 @@
@@ -317,7 +317,7 @@
0 @@ -19,17 +33,17 @@
,

Create a Token

You need at least @@ -50,15 +64,29 @@ exports[`Wallet with BCH balances and tokens 1`] = ` Array [

-

- MigrationTestAlpha -

+

+ MigrationTestAlpha +

+ + + edit.svg + + +
0 @@ -66,17 +94,17 @@
,

Create a Token

You need at least @@ -97,15 +125,29 @@ exports[`Wallet with BCH balances and tokens and state field 1`] = ` Array [

-

- MigrationTestAlpha -

+

+ MigrationTestAlpha +

+ + + edit.svg + + +
0.06 @@ -113,16 +155,16 @@
,

Create a Token

@@ -173,7 +215,7 @@
@@ -211,7 +253,7 @@
@@ -249,7 +291,7 @@
@@ -287,7 +329,7 @@
@@ -325,7 +367,7 @@
@@ -431,7 +473,7 @@
0 @@ -488,17 +544,17 @@
,

Create a Token

You need at least @@ -519,10 +575,24 @@ exports[`Without wallet defined 1`] = ` Array [

+
0 @@ -530,17 +600,17 @@
,

Create a Token

You need at least diff --git a/web/cashtab/src/hooks/useWallet.js b/web/cashtab/src/hooks/useWallet.js --- a/web/cashtab/src/hooks/useWallet.js +++ b/web/cashtab/src/hooks/useWallet.js @@ -743,14 +743,14 @@ return walletToActivate; }; - const renameWallet = async (oldName, newName) => { + const renameSavedWallet = async (oldName, newName) => { // Load savedWallets let savedWallets; try { savedWallets = await localforage.getItem('savedWallets'); } catch (err) { console.log( - `Error in await localforage.getItem("savedWallets") in renameWallet`, + `Error in await localforage.getItem("savedWallets") in renameSavedWallet`, ); console.log(err); return false; @@ -776,7 +776,52 @@ await localforage.setItem('savedWallets', savedWallets); } catch (err) { console.log( - `Error in localforage.setItem("savedWallets", savedWallets) in renameWallet()`, + `Error in localforage.setItem("savedWallets", savedWallets) in renameSavedWallet()`, + ); + return false; + } + return true; + }; + + const renameActiveWallet = async (wallet, oldName, newName) => { + // Load savedWallets + let savedWallets; + try { + savedWallets = await localforage.getItem('savedWallets'); + } catch (err) { + console.log( + `Error in await localforage.getItem("savedWallets") in renameSavedWallet`, + ); + console.log(err); + return false; + } + // Verify that no existing wallet has this name + for (let i = 0; i < savedWallets.length; i += 1) { + if (savedWallets[i].name === newName) { + // return an error + return false; + } + } + if (wallet.name === oldName) { + wallet.name = newName; + setWallet(wallet); + } + + // change name of desired wallet + for (let i = 0; i < savedWallets.length; i += 1) { + if (savedWallets[i].name === oldName) { + // Replace the name of this entry with the new name + savedWallets[i].name = newName; + } + } + // resave savedWallets + try { + // Set walletName as the active wallet + await localforage.setItem('savedWallets', savedWallets); + await localforage.setItem('wallet', wallet); + } catch (err) { + console.log( + `Error in localforage.setItem("wallet", wallet) in renameActiveWallet()`, ); return false; } @@ -1487,7 +1532,8 @@ } }, addNewSavedWallet, - renameWallet, + renameSavedWallet, + renameActiveWallet, deleteWallet, }; };