@@ -2,7 +2,6 @@ import * as React from 'react'
2
2
import { WalletAccountType } from '../../../constants/types'
3
3
import { getLocale } from '../../../../common/locale'
4
4
import {
5
- ConnectHeader ,
6
5
DividerLine ,
7
6
ConnectedAccountItem
8
7
} from '../'
@@ -12,43 +11,83 @@ import {
12
11
StyledWrapper ,
13
12
AddressContainer ,
14
13
AddressScrollContainer ,
15
- AccountsTitle
14
+ AccountsTitle ,
15
+ SiteOriginTitle ,
16
+ HeaderRow ,
17
+ HeaderColumn ,
18
+ FavIcon ,
19
+ NewAccountButton
16
20
} from './style'
17
- // import { getLocale } from '../../../../common/locale'
18
21
19
22
export interface Props {
20
- onDisconnect : ( origin : string , address : string ) => void
23
+ onDisconnect : ( origin : string , address : string , connectedAccounts : WalletAccountType [ ] ) => void
24
+ onConnect : ( origin : string , address : WalletAccountType ) => void
25
+ onSwitchAccount : ( account : WalletAccountType ) => void
26
+ onAddAccount : ( ) => void
27
+ selectedAccount : WalletAccountType
21
28
siteURL : string
22
29
connectedAccounts : WalletAccountType [ ]
30
+ accounts : WalletAccountType [ ]
23
31
}
24
32
25
33
const SitePermissions = ( props : Props ) => {
26
- const { siteURL, connectedAccounts, onDisconnect } = props
34
+ const {
35
+ siteURL,
36
+ connectedAccounts,
37
+ selectedAccount,
38
+ accounts,
39
+ onDisconnect,
40
+ onConnect,
41
+ onSwitchAccount,
42
+ onAddAccount
43
+ } = props
27
44
28
45
const onDisconnectFromOrigin = ( address : string ) => {
29
- onDisconnect ( siteURL , address )
46
+ const newConnectedAccounts = connectedAccounts . filter ( ( accounts ) => accounts . address . toLowerCase ( ) !== address . toLowerCase ( ) )
47
+ onDisconnect ( siteURL , address , newConnectedAccounts )
30
48
}
31
49
50
+ const onConnectToOrigin = ( account : WalletAccountType ) => {
51
+ onConnect ( siteURL , account )
52
+ }
53
+
54
+ const onClickSwitchAccount = ( account : WalletAccountType ) => {
55
+ onSwitchAccount ( account )
56
+ }
57
+
58
+ const checkForPermission = React . useCallback ( ( address : string ) : boolean => {
59
+ return connectedAccounts . some ( account => account . address . toLowerCase ( ) === address . toLowerCase ( ) )
60
+ } , [ connectedAccounts ] )
61
+
62
+ const checkIsActive = React . useCallback ( ( address : string ) : boolean => {
63
+ return address . toLowerCase ( ) === selectedAccount . address . toLowerCase ( )
64
+ } , [ selectedAccount ] )
65
+
32
66
return (
33
67
< StyledWrapper >
34
- < ConnectHeader hideTitle = { true } url = { siteURL } />
68
+ < HeaderRow >
69
+ < FavIcon src = { `chrome://favicon/size/64@1x/${ siteURL } ` } />
70
+ < HeaderColumn >
71
+ < SiteOriginTitle > { siteURL } </ SiteOriginTitle >
72
+ < AccountsTitle > { getLocale ( 'braveWalletSitePermissionsAccounts' ) . replace ( '$1' , connectedAccounts . length . toString ( ) ) } </ AccountsTitle >
73
+ </ HeaderColumn >
74
+ </ HeaderRow >
35
75
< AddressContainer >
36
- < AccountsTitle > { getLocale ( 'braveWalletSitePermissionsAccounts' ) . replace ( '$1' , connectedAccounts . length . toString ( ) ) } </ AccountsTitle >
37
- { connectedAccounts . length !== 0 &&
38
- < >
39
- < DividerLine />
40
- < AddressScrollContainer >
41
- { connectedAccounts . map ( ( account ) => (
42
- < ConnectedAccountItem
43
- key = { account . id }
44
- account = { account }
45
- onDisconnect = { onDisconnectFromOrigin }
46
- />
47
- ) ) }
48
- </ AddressScrollContainer >
49
- < DividerLine />
50
- </ >
51
- }
76
+ < NewAccountButton onClick = { onAddAccount } > { getLocale ( 'braveWalletSitePermissionsNewAccount' ) } </ NewAccountButton >
77
+ < DividerLine />
78
+ < AddressScrollContainer >
79
+ { accounts . map ( ( account ) => (
80
+ < ConnectedAccountItem
81
+ isActive = { checkIsActive ( account . address ) }
82
+ key = { account . id }
83
+ account = { account }
84
+ onDisconnect = { onDisconnectFromOrigin }
85
+ onConnect = { onConnectToOrigin }
86
+ onSwitchAccount = { onClickSwitchAccount }
87
+ hasPermission = { checkForPermission ( account . address ) }
88
+ />
89
+ ) ) }
90
+ </ AddressScrollContainer >
52
91
</ AddressContainer >
53
92
</ StyledWrapper >
54
93
)
0 commit comments