Unverified Commit cb198c41 authored by Andrei Eres's avatar Andrei Eres Committed by GitHub
Browse files

Update nanostores (#90)

* Update nanostores

* Update store names
parent ea9c9b73
Pipeline #166247 passed with stages
in 1 minute and 14 seconds
import { AccountJson } from '@polkadot/extension-base/background/types'
import { createDerived, createStore } from 'nanostores'
import { buildHierarchy } from '../utils/buildHierarchy'
import { action, atom, computed, onStart } from 'nanostores'
import { subscribeAccounts } from '../messaging/uiActions'
import { buildHierarchy } from '../utils/buildHierarchy'
export const accounts = createStore<AccountJson[]>(() => {
accounts.set([])
export const accountsStore = atom<AccountJson[]>([])
onStart(accountsStore, () => {
subscribeAccounts(setAccounts).catch(console.error)
})
export const accountNamesByAddress = createDerived(accounts, (list) =>
export const accountNamesByAddressStore = computed(accountsStore, (list) =>
list.reduce((res, account) => {
res[account.address] = account.name
return res
}, {} as Record<string, string | undefined>)
)
const setAccounts = (list: AccountJson[]) => {
accounts.set(buildHierarchy(list))
}
const setAccounts = action(
accountsStore,
'set_accounts',
(store, list: AccountJson[]) => {
store.set(buildHierarchy(list))
}
)
import { AuthorizeRequest } from '@polkadot/extension-base/background/types'
import { createStore } from 'nanostores'
import { atom, onStart } from 'nanostores'
import { subscribeAuthorizeRequests } from '../messaging/uiActions'
/**
* [
* {
* id: '1631792669113.1',
* request: { origin: 'polkadot-js/apps' },
* url: 'https://polkadot.js.org/apps/#/explorer',
* },
* ]
*/
export const authRequests = createStore<AuthorizeRequest[]>(() => {
authRequests.set([])
subscribeAuthorizeRequests(authRequests.set).catch(console.error)
// [
// {
// id: '1631792669113.1',
// request: { origin: 'polkadot-js/apps' },
// url: 'https://polkadot.js.org/apps/#/explorer',
// },
// ]
export const authRequestsStore = atom<AuthorizeRequest[]>([])
onStart(authRequestsStore, () => {
subscribeAuthorizeRequests(authRequestsStore.set).catch(console.error)
})
import { createStore, update } from 'nanostores'
import { action, atom } from 'nanostores'
import { goHome, goToImport } from '../utils/routing'
type Action = {
......@@ -21,14 +21,20 @@ export const doneAndGoHomeHeaderAction: Action = {
onAction: goHome,
}
export const headerActions = createStore<Action[]>(() => {
headerActions.set([])
})
export const headerActionsStore = atom<Action[]>([])
export const addHeaderAction = (v: Action) => {
update(headerActions, (list) => [...list, v])
}
export const addHeaderAction = action(
headerActionsStore,
'add_header_action',
(store, v: Action) => {
store.set([...store.get(), v])
}
)
export const resetHeaderActions = () => {
headerActions.set([])
}
export const resetHeaderActions = action(
headerActionsStore,
'reset_header_actions',
(store) => {
store.set([])
}
)
import { createStore } from 'nanostores'
import { atom, onStart } from 'nanostores'
import { checkCameraAccess } from '../utils/checkCameraAccess'
import { requestCameraAccess } from '../utils/requestCameraAccess'
export const cameraAllowed = createStore<boolean>(() => {
cameraAllowed.set(true)
// HACK: It doesn't want to work without a little delay
setTimeout(() =>
checkCameraAccess().then(cameraAllowed.set).catch(console.error)
)
export const cameraAllowedStore = atom(false)
onStart(cameraAllowedStore, () => {
checkCameraAccess().then(cameraAllowedStore.set).catch(console.error)
})
export const requestCameraAllowed = () => {
requestCameraAccess().then(cameraAllowed.set).catch(console.error)
requestCameraAccess().then(cameraAllowedStore.set).catch(console.error)
}
import { MetadataRequest } from '@polkadot/extension-base/background/types'
import { createStore } from 'nanostores'
import { atom, onStart } from 'nanostores'
import { subscribeMetadataRequests } from '../messaging/uiActions'
export const metaRequests = createStore<MetadataRequest[]>(() => {
metaRequests.set([])
subscribeMetadataRequests(metaRequests.set).catch(console.error)
export const metaRequestsStore = atom<MetadataRequest[]>([])
onStart(metaRequestsStore, () => {
subscribeMetadataRequests(metaRequestsStore.set).catch(console.error)
})
import { createStore } from 'nanostores'
import { atom, onStart } from 'nanostores'
import { getParam, getPath } from '../utils/routing'
type Page = {
......@@ -12,7 +12,9 @@ function parse() {
router.set({ path, param })
}
export const router = createStore<Page>(() => {
export const router = atom<Page>()
onStart(router, () => {
parse()
window.addEventListener('hashchange', parse)
return () => {
......
import { SigningRequest } from '@polkadot/extension-base/background/types'
import { createStore } from 'nanostores'
import { atom, onStart } from 'nanostores'
import { subscribeSigningRequests } from '../messaging/uiActions'
/**
* [
* {
* account: {
* address: '5FKmibvGwaP4HPAfwvmEHUYTwCfEv6oHJ2psAvBc2NLVrbRr',
* genesisHash:
* '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e',
* name: 'Qqq',
* isExternal: true,
* whenCreated: 1631806811497,
* },
* id: '1631807962840.2',
* request: {
* payload: {
* specVersion: '0x00002382',
* transactionVersion: '0x00000005',
* address: '5FKmibvGwaP4HPAfwvmEHUYTwCfEv6oHJ2psAvBc2NLVrbRr',
* blockHash:
* '0xbf220f228f0a4562525a070d610f4e74d9a08779f7482c5abc18c4ea27a7fb70',
* blockNumber: '0x0070da29',
* era: '0x9502',
* genesisHash:
* '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e',
* method:
* '0x0403008eb591f1deaaeb4901fcabbbd3a809eccb421aca906c38dcb5bf9dad8145d04e0700e8764817',
* nonce: '0x00000000',
* signedExtensions: [
* 'CheckSpecVersion',
* 'CheckTxVersion',
* 'CheckGenesis',
* 'CheckMortality',
* 'CheckNonce',
* 'CheckWeight',
* 'ChargeTransactionPayment',
* ],
* tip: '0x00000000000000000000000000000000',
* version: 4,
* },
* },
* url: 'https://polkadot.js.org/apps/#/accounts',
* },
* ]
*/
export const signRequests = createStore<SigningRequest[]>(() => {
signRequests.set([])
subscribeSigningRequests(signRequests.set).catch(console.error)
// [
// {
// account: {
// address: '5FKmibvGwaP4HPAfwvmEHUYTwCfEv6oHJ2psAvBc2NLVrbRr',
// genesisHash:
// '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e',
// name: 'Qqq',
// isExternal: true,
// whenCreated: 1631806811497,
// },
// id: '1631807962840.2',
// request: {
// payload: {
// specVersion: '0x00002382',
// transactionVersion: '0x00000005',
// address: '5FKmibvGwaP4HPAfwvmEHUYTwCfEv6oHJ2psAvBc2NLVrbRr',
// blockHash:
// '0xbf220f228f0a4562525a070d610f4e74d9a08779f7482c5abc18c4ea27a7fb70',
// blockNumber: '0x0070da29',
// era: '0x9502',
// genesisHash:
// '0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e',
// method:
// '0x0403008eb591f1deaaeb4901fcabbbd3a809eccb421aca906c38dcb5bf9dad8145d04e0700e8764817',
// nonce: '0x00000000',
// signedExtensions: [
// 'CheckSpecVersion',
// 'CheckTxVersion',
// 'CheckGenesis',
// 'CheckMortality',
// 'CheckNonce',
// 'CheckWeight',
// 'ChargeTransactionPayment',
// ],
// tip: '0x00000000000000000000000000000000',
// version: 4,
// },
// },
// url: 'https://polkadot.js.org/apps/#/accounts',
// },
// ]
export const signRequestsStore = atom<SigningRequest[]>([])
onStart(signRequestsStore, () => {
subscribeSigningRequests(signRequestsStore.set).catch(console.error)
})
import { useStore } from 'nanostores/react'
import { useStore } from '@nanostores/react'
import React, { useEffect } from 'react'
import styled from 'styled-components'
import Key from '../components/Key'
import { accounts as accountsStore } from '../../stores/accounts'
import { accountsStore } from '../../stores/accounts'
import {
addHeaderAction,
importHeaderAction,
......
import { AccountJson } from '@polkadot/extension-base/background/types'
import Identicon from '@polkadot/react-identicon'
import { IconTheme } from '@polkadot/react-identicon/types'
import { useStore } from 'nanostores/react'
import { useStore } from '@nanostores/react'
import React, { useEffect, useState } from 'react'
import styled from 'styled-components'
import useMetadata from '../../hooks/useMetadata'
import { useTimedReset } from '../../hooks/useTimedReset'
import { editAccount } from '../../messaging/uiActions'
import { accounts as accountsStore } from '../../stores/accounts'
import { accountsStore } from '../../stores/accounts'
import { DEFAULT_TYPE, RELAY_CHAIN, UNKNOWN } from '../../utils/constants'
import { recodeAddress, Recoded } from '../../utils/recodeAddress'
import copyIcon from '../assets/copy.svg'
......
import { useStore } from 'nanostores/react'
import { useStore } from '@nanostores/react'
import React from 'react'
import styled from 'styled-components'
import { EXT_NAME } from '../../utils/constants'
import logo from '../assets/logo.svg'
import { headerActions } from '../../stores/headerActions'
import { headerActionsStore } from '../../stores/headerActions'
import { BaseProps } from '../types'
import { Button } from './Button'
const Header: React.FC<BaseProps> = ({ className }) => {
const actions = useStore(headerActions)
const actions = useStore(headerActionsStore)
return (
<div className={className}>
......
import { useStore } from 'nanostores/react'
import { useStore } from '@nanostores/react'
import React from 'react'
import styled from 'styled-components'
import {
cameraAllowed as cameraAllowedStore,
requestCameraAllowed,
} from '../../stores/media'
import { cameraAllowedStore, requestCameraAllowed } from '../../stores/media'
import { BaseProps } from '../types'
import { isPopup } from '../../utils/isPopup'
import { windowOpen } from '../../messaging/uiActions'
......
import { PHISHING_PAGE_REDIRECT } from '@polkadot/extension-base/defaults'
import { useStore } from 'nanostores/react'
import { useStore } from '@nanostores/react'
import React from 'react'
import Accounts from '../accounts/Accounts'
import ImportQr from '../accounts/ImportQr'
......@@ -7,10 +7,10 @@ import Authorize from '../requests/Authorize'
import Metadata from '../requests/Metadata'
import Signing from '../requests/Signing'
import PhishingDetected from '../security/PhishingDetected'
import { authRequests as authRequestsStore } from '../../stores/authRequests'
import { metaRequests as metaRequestsStore } from '../../stores/metaRequests'
import { authRequestsStore } from '../../stores/authRequests'
import { metaRequestsStore } from '../../stores/metaRequests'
import { router } from '../../stores/router'
import { signRequests as signRequestsStore } from '../../stores/signRequests'
import { signRequestsStore } from '../../stores/signRequests'
import { exact, exactWithParam } from '../../utils/routing'
const Router: React.FC = () => {
......
import { useStore } from 'nanostores/react'
import { useStore } from '@nanostores/react'
import React, { useState } from 'react'
import { authRequests as authRequestsStore } from '../../stores/authRequests'
import { authRequestsStore } from '../../stores/authRequests'
import AuthorizeRequest from './AuthorizeRequest'
import RequestIndex from './RequestIndex'
......
import { useStore } from 'nanostores/react'
import { useStore } from '@nanostores/react'
import React, { useState } from 'react'
import { metaRequests } from '../../stores/metaRequests'
import { metaRequestsStore } from '../../stores/metaRequests'
import MetadataRequest from './MetadataRequest'
import RequestIndex from './RequestIndex'
const Metadata: React.FC = () => {
const requests = useStore(metaRequests)
const requests = useStore(metaRequestsStore)
const [idx, setIdx] = useState(0)
const request = requests[idx]
......
import { RequestSign } from '@polkadot/extension-base/background/types'
import { SignerPayloadJSON } from '@polkadot/types/types'
import { useStore } from 'nanostores/react'
import { useStore } from '@nanostores/react'
import React, { useState } from 'react'
import { signRequests } from '../../stores/signRequests'
import { signRequestsStore } from '../../stores/signRequests'
import RequestIndex from './RequestIndex'
import SigningRequest from './SigningRequest'
const Signing: React.FC = () => {
const requests = useStore(signRequests)
const requests = useStore(signRequestsStore)
const [idx, setIdx] = useState(0)
const request = requests[idx]
const isTransaction = !!(request?.request?.payload as SignerPayloadJSON)
......
......@@ -4,14 +4,14 @@ import {
} from '@polkadot/extension-base/background/types'
import { wrapBytes } from '@polkadot/extension-dapp/wrapBytes'
import { QrDisplayPayload, QrScanSignature } from '@polkadot/react-qr'
import { useStore } from 'nanostores/react'
import { useStore } from '@nanostores/react'
import React, { useEffect, useRef, useState } from 'react'
import styled from 'styled-components'
import Address from '../components/Address'
import { Button } from '../components/Button'
import {
accountNamesByAddress as accountNamesByAddressStore,
accounts as accountsStore,
accountNamesByAddressStore,
accountsStore,
} from '../../stores/accounts'
import { addHeaderAction, resetHeaderActions } from '../../stores/headerActions'
import { BaseProps } from '../types'
......
import { useStore } from 'nanostores/react'
import { useStore } from '@nanostores/react'
import React from 'react'
import { router } from '../../stores/router'
......
......@@ -1288,6 +1288,11 @@
resolved "https://registry.yarnpkg.com/@ledgerhq/logs/-/logs-6.2.0.tgz#9fb2d6f1811316697f7b3cc14607f6c608912419"
integrity sha512-SLyFyD7ElMhgKWPYedFGCT/ilcbGPgL5hXXYHxOM79Fs5fWi0zaUpt5oGqGMsOAAFaMa9/rbun0pokzPhEFz8A==
"@nanostores/react@^0.1.2":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@nanostores/react/-/react-0.1.2.tgz#5313435164ef6633ac19c710ea25f57213e89ed1"
integrity sha512-H7IFdtCa0SiSoTt6GwOGwtNScLzyZEoafarGZwBicqk5WrtVaPpKMse93v8RcxvRB6MFW6mozQxvaXFfVlpG0g==
"@nodelib/fs.scandir@2.1.5":
version "2.1.5"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
......@@ -4633,10 +4638,10 @@ nanoid@^3.1.30:
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.30.tgz#63f93cc548d2a113dc5dfbc63bfa09e2b9b64362"
integrity sha512-zJpuPDwOv8D2zq2WRoMe1HsfZthVewpel9CAvTfc/2mBD1uUT/agc5f7GHGWXlYkFvi1mVxe4IjvP2HNrop7nQ==
nanostores@^0.4.9:
version "0.4.9"
resolved "https://registry.yarnpkg.com/nanostores/-/nanostores-0.4.9.tgz#1d3af043731dbaf0f74365067759f5e1ca707364"
integrity sha512-B1l3090TtSHmuGzcgKWWT3vnrTzkrJLRAUT2lfXBrJ4OenGxsCiymYH36n+TYJgEeiXQdcD2+TYzTJpB4Lq9GA==
nanostores@^0.5.6:
version "0.5.6"
resolved "https://registry.yarnpkg.com/nanostores/-/nanostores-0.5.6.tgz#d744c511ccbe417a6cdcdde6892196ef7df59cc0"
integrity sha512-GGqPf5sjDF5QM9jVhLpO+LMeTO0IqsCrQxvfUcBXezG/563ZcflCKFFYCokn5lSOv1he5awNHII9qQVqcQQceA==
napi-build-utils@^1.0.1:
version "1.0.2"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment