|
|
@ -1,5 +1,6 @@ |
|
|
|
import PropTypes from 'prop-types' |
|
|
|
import PropTypes from 'prop-types' |
|
|
|
import React, { Component } from 'react' |
|
|
|
import React, { Component } from 'react' |
|
|
|
|
|
|
|
import { Switch, Route } from 'react-router-dom' |
|
|
|
import PermissionsConnectHeader from './permissions-connect-header' |
|
|
|
import PermissionsConnectHeader from './permissions-connect-header' |
|
|
|
import PermissionsConnectFooter from './permissions-connect-footer' |
|
|
|
import PermissionsConnectFooter from './permissions-connect-footer' |
|
|
|
import ChooseAccount from './choose-account' |
|
|
|
import ChooseAccount from './choose-account' |
|
|
@ -9,7 +10,10 @@ import { |
|
|
|
ENVIRONMENT_TYPE_NOTIFICATION, |
|
|
|
ENVIRONMENT_TYPE_NOTIFICATION, |
|
|
|
ENVIRONMENT_TYPE_POPUP, |
|
|
|
ENVIRONMENT_TYPE_POPUP, |
|
|
|
} from '../../../../app/scripts/lib/enums' |
|
|
|
} from '../../../../app/scripts/lib/enums' |
|
|
|
import { DEFAULT_ROUTE, CONNECTED_ROUTE } from '../../helpers/constants/routes' |
|
|
|
import { |
|
|
|
|
|
|
|
DEFAULT_ROUTE, |
|
|
|
|
|
|
|
CONNECTED_ROUTE, |
|
|
|
|
|
|
|
} from '../../helpers/constants/routes' |
|
|
|
import PermissionPageContainer from '../../components/app/permission-page-container' |
|
|
|
import PermissionPageContainer from '../../components/app/permission-page-container' |
|
|
|
|
|
|
|
|
|
|
|
export default class PermissionConnect extends Component { |
|
|
|
export default class PermissionConnect extends Component { |
|
|
@ -29,6 +33,10 @@ export default class PermissionConnect extends Component { |
|
|
|
permissionsRequestId: PropTypes.string, |
|
|
|
permissionsRequestId: PropTypes.string, |
|
|
|
domains: PropTypes.object, |
|
|
|
domains: PropTypes.object, |
|
|
|
history: PropTypes.object.isRequired, |
|
|
|
history: PropTypes.object.isRequired, |
|
|
|
|
|
|
|
connectPath: PropTypes.string.isRequired, |
|
|
|
|
|
|
|
confirmPermissionPath: PropTypes.string.isRequired, |
|
|
|
|
|
|
|
page: PropTypes.string.isRequired, |
|
|
|
|
|
|
|
redirecting: PropTypes.bool, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static defaultProps = { |
|
|
|
static defaultProps = { |
|
|
@ -39,6 +47,7 @@ export default class PermissionConnect extends Component { |
|
|
|
requestAccountTabs: {}, |
|
|
|
requestAccountTabs: {}, |
|
|
|
permissionsRequestId: '', |
|
|
|
permissionsRequestId: '', |
|
|
|
domains: {}, |
|
|
|
domains: {}, |
|
|
|
|
|
|
|
redirecting: false, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static contextTypes = { |
|
|
|
static contextTypes = { |
|
|
@ -46,7 +55,7 @@ export default class PermissionConnect extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
state = { |
|
|
|
state = { |
|
|
|
page: 1, |
|
|
|
redirecting: false, |
|
|
|
selectedAccountAddress: '', |
|
|
|
selectedAccountAddress: '', |
|
|
|
permissionAccepted: null, |
|
|
|
permissionAccepted: null, |
|
|
|
originName: this.props.originName, |
|
|
|
originName: this.props.originName, |
|
|
@ -68,10 +77,10 @@ export default class PermissionConnect extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) { |
|
|
|
componentDidUpdate (prevProps) { |
|
|
|
const { domains, permissionsRequest } = this.props |
|
|
|
const { domains, permissionsRequest, redirecting } = this.props |
|
|
|
const { originName, page } = this.state |
|
|
|
const { originName } = this.state |
|
|
|
|
|
|
|
|
|
|
|
if (!permissionsRequest && prevProps.permissionsRequest && page !== null) { |
|
|
|
if (!permissionsRequest && prevProps.permissionsRequest && !redirecting) { |
|
|
|
const permissionDataForDomain = (domains && domains[originName]) || {} |
|
|
|
const permissionDataForDomain = (domains && domains[originName]) || {} |
|
|
|
const permissionsForDomain = permissionDataForDomain.permissions || [] |
|
|
|
const permissionsForDomain = permissionDataForDomain.permissions || [] |
|
|
|
const prevPermissionDataForDomain = (prevProps.domains && prevProps.domains[originName]) || {} |
|
|
|
const prevPermissionDataForDomain = (prevProps.domains && prevProps.domains[originName]) || {} |
|
|
@ -87,9 +96,8 @@ export default class PermissionConnect extends Component { |
|
|
|
|
|
|
|
|
|
|
|
selectAccount = (address) => { |
|
|
|
selectAccount = (address) => { |
|
|
|
this.setState({ |
|
|
|
this.setState({ |
|
|
|
page: 2, |
|
|
|
|
|
|
|
selectedAccountAddress: address, |
|
|
|
selectedAccountAddress: address, |
|
|
|
}) |
|
|
|
}, () => this.props.history.push(this.props.confirmPermissionPath)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
redirectFlow (accepted) { |
|
|
|
redirectFlow (accepted) { |
|
|
@ -97,7 +105,7 @@ export default class PermissionConnect extends Component { |
|
|
|
const { originName } = this.state |
|
|
|
const { originName } = this.state |
|
|
|
|
|
|
|
|
|
|
|
this.setState({ |
|
|
|
this.setState({ |
|
|
|
page: null, |
|
|
|
redirecting: true, |
|
|
|
permissionAccepted: accepted, |
|
|
|
permissionAccepted: accepted, |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.removeBeforeUnload() |
|
|
|
this.removeBeforeUnload() |
|
|
@ -150,58 +158,69 @@ export default class PermissionConnect extends Component { |
|
|
|
permissionsRequest, |
|
|
|
permissionsRequest, |
|
|
|
addressLastConnectedMap, |
|
|
|
addressLastConnectedMap, |
|
|
|
permissionsRequestId, |
|
|
|
permissionsRequestId, |
|
|
|
|
|
|
|
connectPath, |
|
|
|
|
|
|
|
confirmPermissionPath, |
|
|
|
|
|
|
|
page, |
|
|
|
} = this.props |
|
|
|
} = this.props |
|
|
|
const { page, selectedAccountAddress, permissionAccepted, originName } = this.state |
|
|
|
const { selectedAccountAddress, permissionAccepted, originName, redirecting } = this.state |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="permissions-connect"> |
|
|
|
<div className="permissions-connect"> |
|
|
|
{ page !== null |
|
|
|
{ !redirecting |
|
|
|
? <PermissionsConnectHeader page={page} /> |
|
|
|
? <PermissionsConnectHeader page={page} /> |
|
|
|
: null |
|
|
|
: null |
|
|
|
} |
|
|
|
} |
|
|
|
{ page === 1 |
|
|
|
<Switch> |
|
|
|
? ( |
|
|
|
<Route |
|
|
|
<ChooseAccount |
|
|
|
path={connectPath} |
|
|
|
accounts={accounts} |
|
|
|
exact |
|
|
|
originName={originName} |
|
|
|
render={() => ( |
|
|
|
nativeCurrency={nativeCurrency} |
|
|
|
<ChooseAccount |
|
|
|
selectAccount={(address) => this.selectAccount(address)} |
|
|
|
accounts={accounts} |
|
|
|
selectNewAccountViaModal={() => { |
|
|
|
originName={originName} |
|
|
|
showNewAccountModal({ |
|
|
|
nativeCurrency={nativeCurrency} |
|
|
|
onCreateNewAccount: this.selectAccount, |
|
|
|
selectAccount={(address) => this.selectAccount(address)} |
|
|
|
newAccountNumber, |
|
|
|
selectNewAccountViaModal={() => { |
|
|
|
}) |
|
|
|
showNewAccountModal({ |
|
|
|
}} |
|
|
|
onCreateNewAccount: this.selectAccount, |
|
|
|
addressLastConnectedMap={addressLastConnectedMap} |
|
|
|
newAccountNumber, |
|
|
|
cancelPermissionsRequest={(requestId) => { |
|
|
|
}) |
|
|
|
if (requestId) { |
|
|
|
|
|
|
|
rejectPermissionsRequest(requestId) |
|
|
|
|
|
|
|
this.redirectFlow(false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
permissionsRequestId={permissionsRequestId} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
: ( |
|
|
|
|
|
|
|
<div> |
|
|
|
|
|
|
|
<PermissionPageContainer |
|
|
|
|
|
|
|
request={permissionsRequest || {}} |
|
|
|
|
|
|
|
approvePermissionsRequest={(request, accounts) => { |
|
|
|
|
|
|
|
approvePermissionsRequest(request, accounts) |
|
|
|
|
|
|
|
this.redirectFlow(true) |
|
|
|
|
|
|
|
}} |
|
|
|
}} |
|
|
|
rejectPermissionsRequest={(requestId) => { |
|
|
|
addressLastConnectedMap={addressLastConnectedMap} |
|
|
|
rejectPermissionsRequest(requestId) |
|
|
|
cancelPermissionsRequest={(requestId) => { |
|
|
|
this.redirectFlow(false) |
|
|
|
if (requestId) { |
|
|
|
|
|
|
|
rejectPermissionsRequest(requestId) |
|
|
|
|
|
|
|
this.redirectFlow(false) |
|
|
|
|
|
|
|
} |
|
|
|
}} |
|
|
|
}} |
|
|
|
selectedIdentity={accounts.find((account) => account.address === selectedAccountAddress)} |
|
|
|
permissionsRequestId={permissionsRequestId} |
|
|
|
redirect={page === null} |
|
|
|
|
|
|
|
permissionRejected={ permissionAccepted === false } |
|
|
|
|
|
|
|
/> |
|
|
|
/> |
|
|
|
<PermissionsConnectFooter /> |
|
|
|
)} |
|
|
|
</div> |
|
|
|
/> |
|
|
|
) |
|
|
|
<Route |
|
|
|
} |
|
|
|
path={confirmPermissionPath} |
|
|
|
|
|
|
|
exact |
|
|
|
|
|
|
|
render={() => ( |
|
|
|
|
|
|
|
<div> |
|
|
|
|
|
|
|
<PermissionPageContainer |
|
|
|
|
|
|
|
request={permissionsRequest || {}} |
|
|
|
|
|
|
|
approvePermissionsRequest={(request, accounts) => { |
|
|
|
|
|
|
|
approvePermissionsRequest(request, accounts) |
|
|
|
|
|
|
|
this.redirectFlow(true) |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
rejectPermissionsRequest={(requestId) => { |
|
|
|
|
|
|
|
rejectPermissionsRequest(requestId) |
|
|
|
|
|
|
|
this.redirectFlow(false) |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
selectedIdentity={accounts.find((account) => account.address === selectedAccountAddress)} |
|
|
|
|
|
|
|
redirect={redirecting} |
|
|
|
|
|
|
|
permissionRejected={ permissionAccepted === false } |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
<PermissionsConnectFooter /> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
</Switch> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|