Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
parity-signer-companion
Commits
2e62baf2
Unverified
Commit
2e62baf2
authored
Apr 21, 2022
by
Andrei Eres
Committed by
GitHub
Apr 21, 2022
Browse files
Refactor routing (#113)
parent
25fc38a7
Pipeline
#189615
passed with stages
in 1 minute and 25 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/stores/router.ts
View file @
2e62baf2
import
{
atom
,
onStart
}
from
'
nanostores
'
import
{
getParam
,
getPath
}
from
'
../utils/routing
'
import
{
PHISHING_PAGE_REDIRECT
}
from
'
@polkadot/extension-base/defaults
'
import
{
atom
,
computed
,
onSet
,
onStart
}
from
'
nanostores
'
import
{
exact
,
exactWithParam
,
getParam
,
getPath
}
from
'
../utils/routing
'
import
{
authRequestsStore
}
from
'
./authRequests
'
import
{
metaRequestsStore
}
from
'
./metaRequests
'
import
{
signRequestsStore
}
from
'
./signRequests
'
type
Page
=
{
path
:
string
param
:
string
}
export
const
pageStore
=
atom
<
Page
>
()
function
parse
()
{
const
path
=
getPath
()
const
param
=
getParam
(
path
)
router
.
set
({
path
,
param
})
pageStore
.
set
({
path
,
param
})
}
export
const
router
=
atom
<
Page
>
()
onStart
(
router
,
()
=>
{
onStart
(
pageStore
,
()
=>
{
parse
()
window
.
addEventListener
(
'
hashchange
'
,
parse
)
return
()
=>
{
window
.
removeEventListener
(
'
hashchange
'
,
parse
)
}
})
type
Route
=
'
auth
'
|
'
meta
'
|
'
sign
'
|
'
import
'
|
'
phishing
'
|
'
accounts
'
export
const
routeStore
=
computed
(
[
pageStore
,
authRequestsStore
,
metaRequestsStore
,
signRequestsStore
],
({
path
},
authRequests
,
metaRequests
,
signRequests
)
=>
{
if
(
exact
(
path
,
''
)
&&
authRequests
?.
length
>
0
)
return
'
auth
'
if
(
exact
(
path
,
''
)
&&
metaRequests
?.
length
>
0
)
return
'
meta
'
if
(
exact
(
path
,
''
)
&&
signRequests
?.
length
>
0
)
return
'
sign
'
if
(
exact
(
path
,
'
/account/import
'
))
return
'
import
'
if
(
exactWithParam
(
path
,
`
${
PHISHING_PAGE_REDIRECT
}
/:website`
))
return
'
phishing
'
return
'
accounts
'
as
Route
}
)
onSet
(
routeStore
,
({
newValue
,
abort
})
=>
{
if
(
routeStore
.
get
()
===
newValue
)
abort
()
})
src/ui/global/Router.tsx
View file @
2e62baf2
import
{
PHISHING_PAGE_REDIRECT
}
from
'
@polkadot/extension-base/defaults
'
import
{
useStore
}
from
'
@nanostores/react
'
import
React
from
'
react
'
import
{
routeStore
}
from
'
../../stores/router
'
import
Accounts
from
'
../accounts/Accounts
'
import
ImportQr
from
'
../accounts/ImportQr
'
import
Authorize
from
'
../requests/Authorize
'
import
Metadata
from
'
../requests/Metadata
'
import
Signing
from
'
../requests/Signing
'
import
PhishingDetected
from
'
../security/PhishingDetected
'
import
{
authRequestsStore
}
from
'
../../stores/authRequests
'
import
{
metaRequestsStore
}
from
'
../../stores/metaRequests
'
import
{
router
}
from
'
../../stores/router
'
import
{
signRequestsStore
}
from
'
../../stores/signRequests
'
import
{
exact
,
exactWithParam
}
from
'
../../utils/routing
'
const
Router
:
React
.
FC
=
()
=>
{
const
{
path
}
=
useStore
(
router
)
const
authRequests
=
useStore
(
authRequestsStore
)
const
metaRequests
=
useStore
(
metaRequestsStore
)
const
signRequests
=
useStore
(
signRequestsStore
)
const
route
=
useStore
(
routeStore
)
if
(
exact
(
path
,
''
)
&&
authRequests
?.
length
)
return
<
Authorize
/>
if
(
exact
(
path
,
''
)
&&
metaRequests
?.
length
)
return
<
Metadata
/>
if
(
exact
(
path
,
''
)
&&
signRequests
?.
length
)
return
<
Signing
/>
if
(
exact
(
path
,
'
/account/import
'
))
return
<
ImportQr
/>
if
(
exactWithParam
(
path
,
`
${
PHISHING_PAGE_REDIRECT
}
/:website`
))
return
<
PhishingDetected
/>
return
<
Accounts
/>
return
(
<>
{
route
===
'
auth
'
&&
<
Authorize
/>
}
{
route
===
'
meta
'
&&
<
Metadata
/>
}
{
route
===
'
sign
'
&&
<
Signing
/>
}
{
route
===
'
import
'
&&
<
ImportQr
/>
}
{
route
===
'
phishing
'
&&
<
PhishingDetected
/>
}
{
route
===
'
accounts
'
&&
<
Accounts
/>
}
</>
)
}
export
default
Router
src/ui/security/PhishingDetected.tsx
View file @
2e62baf2
import
{
useStore
}
from
'
@nanostores/react
'
import
React
from
'
react
'
import
{
router
}
from
'
../../stores/router
'
import
{
pageStore
}
from
'
../../stores/router
'
const
PhishingDetected
:
React
.
FC
=
()
=>
{
const
{
param
:
website
}
=
useStore
(
router
)
const
{
param
:
website
}
=
useStore
(
pageStore
)
const
decodedWebsite
=
decodeURIComponent
(
website
)
return
(
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment