Share PASSWORD_EXPIRY default between components (#463)
* generic time * share expiry minutes and ms * edit translation
This commit is contained in:
@@ -5,6 +5,7 @@ import { MetadataDef } from '@polkadot/extension-inject/types';
|
||||
import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
|
||||
import { AccountJson, AuthorizeRequest, MessageTypes, MetadataRequest, RequestAccountCreateExternal, RequestAccountCreateSuri, RequestAccountEdit, RequestAccountExport, RequestAccountShow, RequestAccountTie, RequestAccountValidate, RequestAuthorizeApprove, RequestAuthorizeReject, RequestDeriveCreate, ResponseDeriveValidate, RequestMetadataApprove, RequestMetadataReject, RequestSigningApprovePassword, RequestSigningApproveSignature, RequestSigningCancel, RequestSigningIsLocked, RequestSeedCreate, RequestTypes, ResponseAccountExport, RequestAccountForget, ResponseSeedCreate, RequestSeedValidate, RequestDeriveValidate, ResponseSeedValidate, ResponseType, SigningRequest, RequestJsonRestore, ResponseJsonRestore, RequestAccountChangePassword } from '../types';
|
||||
|
||||
import { PASSWORD_EXPIRY_MS } from '@polkadot/extension-base/defaults';
|
||||
import chrome from '@polkadot/extension-inject/chrome';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import accountsObservable from '@polkadot/ui-keyring/observable/accounts';
|
||||
@@ -20,7 +21,6 @@ type CachedUnlocks = Record<string, number>;
|
||||
|
||||
const SEED_DEFAULT_LENGTH = 12;
|
||||
const SEED_LENGTHS = [12, 15, 18, 21, 24];
|
||||
const PASSWORD_EXPIRY = 15 * 60 * 1000;
|
||||
|
||||
// a global registry to use internally
|
||||
const registry = new TypeRegistry();
|
||||
@@ -311,7 +311,7 @@ export default class Extension {
|
||||
const savedExpiry = this.#cachedUnlocks[request.payload.address] || 0;
|
||||
|
||||
if (isSavedPass) {
|
||||
this.#cachedUnlocks[request.payload.address] = now + PASSWORD_EXPIRY;
|
||||
this.#cachedUnlocks[request.payload.address] = now + PASSWORD_EXPIRY_MS;
|
||||
} else if (savedExpiry < now) {
|
||||
this.#cachedUnlocks[request.payload.address] = 0;
|
||||
pair.lock();
|
||||
|
||||
@@ -3,8 +3,12 @@
|
||||
|
||||
const PORT_CONTENT = 'content';
|
||||
const PORT_EXTENSION = 'extension';
|
||||
const PASSWORD_EXPIRY_MIN = 15;
|
||||
const PASSWORD_EXPIRY_MS = PASSWORD_EXPIRY_MIN * 60 * 1000;
|
||||
|
||||
export {
|
||||
PASSWORD_EXPIRY_MIN,
|
||||
PASSWORD_EXPIRY_MS,
|
||||
PORT_CONTENT,
|
||||
PORT_EXTENSION
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import { AccountJson, RequestSign } from '@polkadot/extension-base/background/ty
|
||||
import { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
|
||||
|
||||
import React, { useCallback, useContext, useState, useEffect } from 'react';
|
||||
import { PASSWORD_EXPIRY_MIN } from '@polkadot/extension-base/defaults';
|
||||
import { TypeRegistry } from '@polkadot/types';
|
||||
|
||||
import { ActionBar, ActionContext, Address, Button, ButtonArea, Checkbox, Link, VerticalSpace } from '../../components';
|
||||
@@ -114,7 +115,7 @@ export default function Request ({ account: { isExternal }, buttonText, isFirst,
|
||||
[onAction, signId]
|
||||
);
|
||||
|
||||
const signButton = isLocked
|
||||
const SignButton = () => isLocked
|
||||
? (
|
||||
<Unlock
|
||||
buttonText={buttonText}
|
||||
@@ -124,7 +125,10 @@ export default function Request ({ account: { isExternal }, buttonText, isFirst,
|
||||
>
|
||||
<Checkbox
|
||||
checked={!!isSavedPass}
|
||||
label={t<string>("Don't ask me again for the next 15 minutes")}
|
||||
label={t<string>(
|
||||
"Don't ask me again for the next {{expiration}} minutes",
|
||||
{ replace: { expiration: PASSWORD_EXPIRY_MIN } }
|
||||
)}
|
||||
onChange={setIsSavedPass}
|
||||
/>
|
||||
</Unlock>
|
||||
@@ -167,7 +171,7 @@ export default function Request ({ account: { isExternal }, buttonText, isFirst,
|
||||
)
|
||||
}
|
||||
<SignArea>
|
||||
{isFirst && !isExternal && signButton}
|
||||
{isFirst && !isExternal && <SignButton/>}
|
||||
<CancelButton>
|
||||
<Link
|
||||
isDanger
|
||||
@@ -193,7 +197,7 @@ export default function Request ({ account: { isExternal }, buttonText, isFirst,
|
||||
/>
|
||||
<VerticalSpace />
|
||||
<SignArea>
|
||||
{!isExternal && signButton}
|
||||
{!isExternal && <SignButton/>}
|
||||
<CancelButton>
|
||||
<Link
|
||||
isDanger
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
"Sign the transaction": "",
|
||||
"Sign the message": "",
|
||||
"Scan signature via camera": "",
|
||||
"Don't ask me again for the next 15 minutes": "",
|
||||
"Don't ask me again for the next {{expiration}} minutes": "",
|
||||
"Password for this account": "",
|
||||
"Welcome": "",
|
||||
"Before we start, just a couple of notes regarding use:": "",
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
"Sign the transaction": "签名此交易",
|
||||
"Sign the message": "签名此消息",
|
||||
"Scan signature via camera": "通过摄像头扫描签名",
|
||||
"Don't ask me again for the next 15 minutes": "在接下来的15分钟内别再问我了",
|
||||
"Don't ask me again for the next {{expiration}} minutes": "在接下来的{{expiration}}分钟内别再问我了",
|
||||
"Password for this account": "此帐户密码",
|
||||
"Welcome": "欢迎",
|
||||
"Before we start, just a couple of notes regarding use:": "在我们开始之前,只是一些关于使用的注意事项:",
|
||||
|
||||
Reference in New Issue
Block a user