parent
00b42e9f97
commit
2d16ecea5a
@ -13,6 +13,9 @@ Changes:
|
|||||||
- Add option to not ask password for 15 minutes (when signing transactions)
|
- Add option to not ask password for 15 minutes (when signing transactions)
|
||||||
- Derived accounts uses the parent genesisHash by default (attaches to same chain)
|
- Derived accounts uses the parent genesisHash by default (attaches to same chain)
|
||||||
- Make import from seed, QR & JSON options available on first-start
|
- Make import from seed, QR & JSON options available on first-start
|
||||||
|
- Adjust popup width, allowing full display of e.g. addresses
|
||||||
|
- Handling signing rejections (any order) transparently
|
||||||
|
- Small overall UI and use adjustments
|
||||||
- Latest upstream polkadot-js dependencies
|
- Latest upstream polkadot-js dependencies
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,12 +4,8 @@
|
|||||||
|
|
||||||
import { AccountJson } from '@polkadot/extension-base/background/types';
|
import { AccountJson } from '@polkadot/extension-base/background/types';
|
||||||
|
|
||||||
function childrenCount (accounts: AccountJson[], parentAddress: string): number {
|
export function nextDerivationPath (accounts: AccountJson[], parentAddress: string): string {
|
||||||
return accounts.filter((account) => account.parentAddress === parentAddress).length;
|
const siblingsCount = accounts.filter((account) => account.parentAddress === parentAddress).length;
|
||||||
}
|
|
||||||
|
|
||||||
export const nextDerivationPath = (accounts: AccountJson[], parentAddress: string): string => {
|
|
||||||
const siblingsCount = childrenCount(accounts, parentAddress);
|
|
||||||
|
|
||||||
return `//${siblingsCount}`;
|
return `//${siblingsCount}`;
|
||||||
};
|
}
|
||||||
|
|||||||
@ -6,7 +6,8 @@ interface InputError {
|
|||||||
errorDescription: string;
|
errorDescription: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Result<T> = { error: InputError } | { ok: T }
|
export type Result<T> = { error: InputError } | { ok: T };
|
||||||
|
|
||||||
export const Result = {
|
export const Result = {
|
||||||
error: <T>(errorDescription: string): Result<T> => ({ error: { errorDescription } }),
|
error: <T>(errorDescription: string): Result<T> => ({ error: { errorDescription } }),
|
||||||
isError<T> (value: Result<T>): value is ({ error: InputError }) {
|
isError<T> (value: Result<T>): value is ({ error: InputError }) {
|
||||||
@ -20,31 +21,32 @@ export const Result = {
|
|||||||
|
|
||||||
export declare type Validator<T> = (value: T) => Result<T> | Promise<Result<T>>;
|
export declare type Validator<T> = (value: T) => Result<T> | Promise<Result<T>>;
|
||||||
|
|
||||||
export const allOf = <T>(...validators: Validator<T>[]): Validator<T> => async (value: T): Promise<Result<T>> => {
|
export function allOf <T> (...validators: Validator<T>[]): Validator<T> {
|
||||||
for (const validator of validators) {
|
return async (value: T): Promise<Result<T>> => {
|
||||||
const validationResult = await validator(value);
|
for (const validator of validators) {
|
||||||
|
const validationResult = await validator(value);
|
||||||
|
|
||||||
if (Result.isError(validationResult)) {
|
if (Result.isError(validationResult)) {
|
||||||
return validationResult;
|
return validationResult;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return Result.ok(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const isNotShorterThan = (minLength: number, errorText: string): Validator<string> =>
|
|
||||||
(value: string): Result<string> => {
|
|
||||||
if (value.length < minLength) {
|
|
||||||
return Result.error(errorText);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.ok(value);
|
return Result.ok(value);
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const isSameAs = <T>(expectedValue: T, errorText: string): Validator<T> => (value: T): Result<T> => {
|
export function isNotShorterThan (minLength: number, errorText: string): Validator<string> {
|
||||||
if (value !== expectedValue) {
|
return (value: string): Result<string> => {
|
||||||
return Result.error(errorText);
|
return value.length < minLength
|
||||||
}
|
? Result.error(errorText)
|
||||||
|
: Result.ok(value);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return Result.ok(value);
|
export function isSameAs <T> (expectedValue: T, errorText: string): Validator<T> {
|
||||||
};
|
return (value: T): Result<T> => {
|
||||||
|
return value !== expectedValue
|
||||||
|
? Result.error(errorText)
|
||||||
|
: Result.ok(value);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user