Skip to content

Commit f928d7a

Browse files
authored
Merge pull request #10832 from brave/pr10823_switch-evm-networks-ui_1.32.x
Built Out Switch EVM Network Panel UI (uplift to 1.32.x)
2 parents bf9117a + cb7fbf4 commit f928d7a

File tree

9 files changed

+83
-29
lines changed

9 files changed

+83
-29
lines changed

components/brave_wallet/browser/brave_wallet_constants.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ constexpr webui::LocalizedString kLocalizedStrings[] = {
322322
IDS_BRAVE_WALLET_ALLOW_SPEND_PROPOSED_ALLOWANCE},
323323
{"braveWalletAllowAddNetworkTitle",
324324
IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_TITLE},
325+
{"braveWalletAllowChangeNetworkTitle",
326+
IDS_BRAVE_WALLET_ALLOW_CHANGE_NETWORK_TITLE},
327+
{"braveWalletAllowChangeNetworkDescription",
328+
IDS_BRAVE_WALLET_ALLOW_CHANGE_NETWORK_DESCRIPTION},
329+
{"braveWalletAllowChangeNetworkButton",
330+
IDS_BRAVE_WALLET_ALLOW_CHANGE_NETWORK_BUTTON},
325331
{"braveWalletAllowAddNetworkDescription",
326332
IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_DESCRIPTION},
327333
{"braveWalletAllowAddNetworkLearnMoreButton",
@@ -330,8 +336,8 @@ constexpr webui::LocalizedString kLocalizedStrings[] = {
330336
{"braveWalletAllowAddNetworkUrl", IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_URL},
331337
{"braveWalletAllowAddNetworkDetailsButton",
332338
IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_DETAILS_BUTTON},
333-
{"braveWalletAllowAddNetworkApproveButton",
334-
IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_APPROVE_BUTTON},
339+
{"braveWalletAllowAddNetworkButton",
340+
IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_BUTTON},
335341
{"braveWalletAllowAddNetworkChainID",
336342
IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_CHAIN_I_D},
337343
{"braveWalletAllowAddNetworkCurrencySymbol",

components/brave_wallet_ui/components/extension/allow-add-network-panel/index.tsx renamed to components/brave_wallet_ui/components/extension/allow-add-change-network-panel/index.tsx

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import * as React from 'react'
22
import { create } from 'ethereum-blockies'
33
import { EthereumChain } from '../../../constants/types'
44
import { reduceAddress } from '../../../utils/reduce-address'
5+
import { reduceNetworkDisplayName } from '../../../utils/network-utils'
56
import { getLocale } from '../../../../common/locale'
6-
import { NavButton, PanelTab } from '../'
7+
import { NavButton, PanelTab } from '..'
78

89
// Styled Components
910
import {
@@ -33,17 +34,23 @@ import {
3334
export type tabs = 'network' | 'details'
3435

3536
export interface Props {
37+
siteOrigin: string
3638
networkPayload: EthereumChain
39+
panelType: 'add' | 'change'
3740
onCancel: () => void
38-
onApprove: () => void
41+
onApproveAddNetwork: () => void
42+
onApproveChangeNetwork: () => void
3943
onLearnMore: () => void
4044
}
4145

42-
function AllowAddNetworkPanel (props: Props) {
46+
function AllowAddChangeNetworkPanel (props: Props) {
4347
const {
48+
siteOrigin,
4449
networkPayload,
50+
panelType,
4551
onCancel,
46-
onApprove,
52+
onApproveAddNetwork,
53+
onApproveChangeNetwork,
4754
onLearnMore
4855
} = props
4956
const rpcUrl = networkPayload.rpcUrls ? (new URL(networkPayload.rpcUrls[0])).hostname : ''
@@ -61,17 +68,33 @@ function AllowAddNetworkPanel (props: Props) {
6168
return (
6269
<StyledWrapper>
6370
<TopRow>
64-
<NetworkText>{networkPayload.chainName}</NetworkText>
71+
<NetworkText>{reduceNetworkDisplayName(networkPayload.chainName)}</NetworkText>
6572
<AddressAndOrb>
6673
<AddressText>{reduceAddress(rpcUrl)}</AddressText>
6774
<AccountCircle orb={orb} />
6875
</AddressAndOrb>
6976
</TopRow>
7077
<CenterColumn>
71-
<FavIcon src='' />
72-
<URLText>{rpcUrl}</URLText>
73-
<PanelTitle>{getLocale('braveWalletAllowAddNetworkTitle')}</PanelTitle>
74-
<Description>{getLocale('braveWalletAllowAddNetworkDescription')} <DetailsButton onClick={onLearnMore}>{getLocale('braveWalletAllowAddNetworkLearnMoreButton')}</DetailsButton></Description>
78+
<FavIcon src={`chrome://favicon/size/64@1x/${siteOrigin}`} />
79+
<URLText>{siteOrigin}</URLText>
80+
<PanelTitle>
81+
{panelType === 'change'
82+
? getLocale('braveWalletAllowChangeNetworkTitle')
83+
: getLocale('braveWalletAllowAddNetworkTitle')
84+
}
85+
</PanelTitle>
86+
<Description>
87+
{panelType === 'change'
88+
? getLocale('braveWalletAllowChangeNetworkDescription')
89+
: getLocale('braveWalletAllowAddNetworkDescription')}{' '}
90+
{panelType === 'add' &&
91+
<DetailsButton
92+
onClick={onLearnMore}
93+
>
94+
{getLocale('braveWalletAllowAddNetworkLearnMoreButton')}
95+
</DetailsButton>
96+
}
97+
</Description>
7598
<TabRow>
7699
<PanelTab
77100
isSelected={selectedTab === 'network'}
@@ -119,12 +142,20 @@ function AllowAddNetworkPanel (props: Props) {
119142
/>
120143
<NavButton
121144
buttonType='confirm'
122-
text={getLocale('braveWalletAllowAddNetworkApproveButton')}
123-
onSubmit={onApprove}
145+
text={
146+
panelType === 'change'
147+
? getLocale('braveWalletAllowChangeNetworkButton')
148+
: getLocale('braveWalletAllowAddNetworkButton')
149+
}
150+
onSubmit={
151+
panelType === 'add'
152+
? onApproveAddNetwork
153+
: onApproveChangeNetwork
154+
}
124155
/>
125156
</ButtonRow>
126157
</StyledWrapper>
127158
)
128159
}
129160

130-
export default AllowAddNetworkPanel
161+
export default AllowAddChangeNetworkPanel

components/brave_wallet_ui/components/extension/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import WelcomePanel from './welcome-panel'
1010
import Panel from './panel'
1111
import PanelHeader from './panel-header'
1212
import SignPanel from './sign-panel'
13-
import AllowAddNetworkPanel from './allow-add-network-panel'
13+
import AllowAddChangeNetworkPanel from './allow-add-change-network-panel'
1414
import ConfirmTransactionPanel from './confirm-transaction-panel'
1515
import PanelTab from './panel-tab'
1616
import ConnectHardwareWalletPanel from './connect-hardware-wallet-panel'
@@ -34,7 +34,7 @@ export {
3434
PanelHeader,
3535
WelcomePanel,
3636
SignPanel,
37-
AllowAddNetworkPanel,
37+
AllowAddChangeNetworkPanel,
3838
ConfirmTransactionPanel,
3939
PanelTab,
4040
TransactionDetailBox,

components/brave_wallet_ui/components/extension/shared-panel-styles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const PanelTitle = styled.span`
7070
line-height: 20px;
7171
letter-spacing: 0.04em;
7272
text-align: center;
73+
width: 90%;
7374
color: ${(p) => p.theme.color.text01};
7475
font-weight: 600;
7576
margin-bottom: 6px;

components/brave_wallet_ui/panel/container.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
Panel,
1313
WelcomePanel,
1414
SignPanel,
15-
AllowAddNetworkPanel,
15+
AllowAddChangeNetworkPanel,
1616
ConfirmTransactionPanel,
1717
ConnectHardwareWalletPanel,
1818
SitePermissions
@@ -396,6 +396,10 @@ function Container (props: Props) {
396396
props.walletPanelActions.addEthereumChainRequestCompleted({ chainId: networkPayload.chainId, approved: true })
397397
}
398398

399+
const onApproveChangeNetwork = () => {
400+
// Logic here to approve changing networks
401+
}
402+
399403
const onCancelAddNetwork = () => {
400404
props.walletPanelActions.addEthereumChainRequestCompleted({ chainId: networkPayload.chainId, approved: false })
401405
}
@@ -527,11 +531,14 @@ function Container (props: Props) {
527531
return (
528532
<PanelWrapper isLonger={true}>
529533
<LongWrapper>
530-
<AllowAddNetworkPanel
531-
onApprove={onApproveAddNetwork}
534+
<AllowAddChangeNetworkPanel
535+
siteOrigin={activeOrigin}
536+
onApproveAddNetwork={onApproveAddNetwork}
537+
onApproveChangeNetwork={onApproveChangeNetwork}
532538
onCancel={onCancelAddNetwork}
533539
onLearnMore={onNetworkLearnMore}
534540
networkPayload={networkPayload}
541+
panelType='add'
535542
/>
536543
</LongWrapper>
537544
</PanelWrapper>

components/brave_wallet_ui/stories/locale.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,20 @@ provideStrings({
270270
braveWalletAllowSpendRejectButton: 'Reject',
271271
braveWalletAllowSpendConfirmButton: 'Confirm',
272272

273-
// Allow Add Network Panel
273+
// Allow Add or Change Network Panel
274274
braveWalletAllowAddNetworkTitle: 'Allow this site to add a network?',
275275
braveWalletAllowAddNetworkDescription: 'This will allow this network to be used within Brave Wallet.',
276276
braveWalletAllowAddNetworkLearnMoreButton: 'Learn more.',
277277
braveWalletAllowAddNetworkName: 'Network name',
278278
braveWalletAllowAddNetworkUrl: 'Network URL',
279279
braveWalletAllowAddNetworkDetailsButton: 'View all details',
280-
braveWalletAllowAddNetworkApproveButton: 'Approve',
280+
braveWalletAllowAddNetworkButton: 'Approve',
281281
braveWalletAllowAddNetworkChainID: 'Chain ID',
282282
braveWalletAllowAddNetworkCurrencySymbol: 'Currency symbol',
283283
braveWalletAllowAddNetworkExplorer: 'Block explorer URL',
284+
braveWalletAllowChangeNetworkTitle: 'Allow this site to switch the network?',
285+
braveWalletAllowChangeNetworkDescription: 'This will switch the network to a previously added network.',
286+
braveWalletAllowChangeNetworkButton: 'Switch network',
284287

285288
// Confirm Transaction Panel
286289
braveWalletConfirmTransactionTotal: 'Total',

components/brave_wallet_ui/stories/wallet-extension-panels.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Panel,
88
WelcomePanel,
99
SignPanel,
10-
AllowAddNetworkPanel,
10+
AllowAddChangeNetworkPanel,
1111
ConfirmTransactionPanel,
1212
ConnectHardwareWalletPanel,
1313
SitePermissions
@@ -194,10 +194,10 @@ _ConfirmTransaction.story = {
194194
name: 'Confirm Transaction'
195195
}
196196

197-
export const _AllowAddNetwork = () => {
197+
export const _AllowAddChangeNetwork = () => {
198198

199199
const onApprove = () => {
200-
alert('Approved Adding Network')
200+
alert('Will Approve adding or chainging networks')
201201
}
202202

203203
const onCancel = () => {
@@ -210,8 +210,11 @@ export const _AllowAddNetwork = () => {
210210

211211
return (
212212
<StyledExtensionWrapperLonger>
213-
<AllowAddNetworkPanel
214-
onApprove={onApprove}
213+
<AllowAddChangeNetworkPanel
214+
siteOrigin='https://app.uniswap.org'
215+
panelType='change'
216+
onApproveAddNetwork={onApprove}
217+
onApproveChangeNetwork={onApprove}
215218
onCancel={onCancel}
216219
networkPayload={mockNetworks[0]}
217220
onLearnMore={onLearnMore}
@@ -220,8 +223,8 @@ export const _AllowAddNetwork = () => {
220223
)
221224
}
222225

223-
_AllowAddNetwork.story = {
224-
name: 'Allow Add Network'
226+
_AllowAddChangeNetwork.story = {
227+
name: 'Allow Add or Change Network'
225228
}
226229

227230
export const _SignData = () => {

components/resources/wallet_strings.grdp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,13 @@
226226
<message name="IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_NAME" desc="Add network panel name label">Network name</message>
227227
<message name="IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_URL" desc="Add network panel url label">Network URL</message>
228228
<message name="IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_DETAILS_BUTTON" desc="Add network panel all details button">View all details</message>
229-
<message name="IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_APPROVE_BUTTON" desc="Add network panel approve button">Approve</message>
229+
<message name="IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_BUTTON" desc="Add network panel button">Approve</message>
230230
<message name="IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_CHAIN_I_D" desc="Add network panel chain id label">Chain ID</message>
231231
<message name="IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_CURRENCY_SYMBOL" desc="Add network panel symbol label">Currency symbol</message>
232232
<message name="IDS_BRAVE_WALLET_ALLOW_ADD_NETWORK_EXPLORER" desc="Add network explorer label">Block explorer URL</message>
233+
<message name="IDS_BRAVE_WALLET_ALLOW_CHANGE_NETWORK_TITLE" desc="Change network panel title">Allow this site to switch the network?</message>
234+
<message name="IDS_BRAVE_WALLET_ALLOW_CHANGE_NETWORK_DESCRIPTION" desc="Change network panel description">This will switch the network to a previously added network.</message>
235+
<message name="IDS_BRAVE_WALLET_ALLOW_CHANGE_NETWORK_BUTTON" desc="Change network panel button">Switch network</message>
233236
<message name="IDS_BRAVE_WALLET_CONFIRM_TRANSACTION_TOTAL" desc="Confirm transaction panel total label">Total</message>
234237
<message name="IDS_BRAVE_WALLET_CONFIRM_TRANSACTION_GAS_FEE" desc="Confirm transaction panel label">Gas fee</message>
235238
<message name="IDS_BRAVE_WALLET_CONFIRM_TRANSACTION_BID" desc="Confirm transaction panel bid label">Bid</message>

0 commit comments

Comments
 (0)