Convert all to named imports (#414)

This commit is contained in:
Jaco Greeff
2020-12-09 01:41:44 +01:00
committed by GitHub
parent a5434d4428
commit 7e494673e0
69 changed files with 175 additions and 193 deletions
+1 -1
View File
@@ -29,7 +29,7 @@
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@polkadot/dev": "^0.60.12",
"@polkadot/dev": "^0.60.13",
"@polkadot/ts": "^0.3.57",
"@types/jest": "^26.0.17",
"babel-plugin-transform-vue-template": "^0.4.2",
+3 -3
View File
@@ -4,9 +4,9 @@
import React, { useCallback, useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
import Identicon from '@polkadot/react-identicon';
import keyring from '@polkadot/ui-keyring';
import settings from '@polkadot/ui-settings';
import { Identicon } from '@polkadot/react-identicon';
import { keyring } from '@polkadot/ui-keyring';
import { settings } from '@polkadot/ui-settings';
import { cryptoWaitReady, mnemonicGenerate } from '@polkadot/util-crypto';
interface Props {
+2 -2
View File
@@ -5,8 +5,8 @@ import type { Prefix } from '@polkadot/util-crypto/address/types';
import Vue, { VNode } from 'vue';
import keyring from '@polkadot/ui-keyring';
import settings from '@polkadot/ui-settings';
import { keyring } from '@polkadot/ui-keyring';
import { settings } from '@polkadot/ui-settings';
import { cryptoWaitReady, mnemonicGenerate } from '@polkadot/util-crypto';
import Identicon from '@polkadot/vue-identicon';
+2 -2
View File
@@ -6,8 +6,8 @@ import { Button, SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, View } f
import { Colors } from 'react-native/Libraries/NewAppScreen';
import Identicon from '@polkadot/reactnative-identicon';
import keyring from '@polkadot/ui-keyring';
import settings from '@polkadot/ui-settings';
import { keyring } from '@polkadot/ui-keyring';
import { settings } from '@polkadot/ui-settings';
import { cryptoWaitReady, mnemonicGenerate } from '@polkadot/util-crypto';
const styles = StyleSheet.create({
+1 -1
View File
@@ -21,4 +21,4 @@ const transports: TransportDef[] = [
}
];
export default transports;
export { transports };
-1
View File
@@ -1,7 +1,6 @@
// Copyright 2017-2020 @polkadot/ledger authors & contributors
// SPDX-License-Identifier: Apache-2.0
declare module '@ledgerhq/hw-transport-node-hid-noevents' {
import Transport from '@ledgerhq/hw-transport';
+1 -1
View File
@@ -14,4 +14,4 @@ const transports: TransportDef[] = [
}
];
export default transports;
export { transports };
@@ -5,4 +5,4 @@ import type { TransportDef } from './types';
const transports: TransportDef[] = [];
export default transports;
export { transports };
+2 -2
View File
@@ -6,7 +6,7 @@ import type { AccountOptions, LedgerAddress, LedgerSignature, LedgerTypes, Ledge
import { newKusamaApp, newPolkadotApp, ResponseBase, SubstrateApp } from '@zondax/ledger-polkadot';
import transports from '@polkadot/ledger-transports';
import { transports } from '@polkadot/ledger-transports';
import { assert, bufferToU8a, u8aToBuffer, u8aToHex } from '@polkadot/util';
export const LEDGER_DEFAULT_ACCOUNT = 0x80000000;
@@ -27,7 +27,7 @@ type Chain = keyof typeof APPS;
// A very basic wrapper for a ledger app -
// - it connects automatically, creating an app as required
// - Promises return errors (instead of wrapper errors)
export default class Ledger {
export class Ledger {
#app: SubstrateApp | null = null;
#chain: Chain;
+3 -3
View File
@@ -6,7 +6,7 @@ import ReactDOM from 'react-dom';
import { encodeAddress, randomAsU8a } from '@polkadot/util-crypto';
import IdentityIcon from '.';
import { Identicon } from '.';
const THEMES = ['beachball', 'polkadot', 'substrate'];
@@ -24,7 +24,7 @@ export default class Demo extends React.PureComponent {
<div>
<div>
{identities.map((value, index): React.ReactNode => (
<IdentityIcon
<Identicon
key={value.toString()}
theme={THEMES[index % THEMES.length] as 'empty'}
value={value}
@@ -33,7 +33,7 @@ export default class Demo extends React.PureComponent {
</div>
<div>
{THEMES.map((theme): React.ReactNode => (
<IdentityIcon
<Identicon
key={theme}
theme={theme as 'empty'}
value='5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
+3 -3
View File
@@ -8,7 +8,7 @@ import React from 'react';
import CopyToClipboard from 'react-copy-to-clipboard';
import styled from 'styled-components';
import settings, { ICON_DEFAULT_HOST } from '@polkadot/ui-settings';
import { ICON_DEFAULT_HOST, settings } from '@polkadot/ui-settings';
import { isHex, isU8a, u8aToHex } from '@polkadot/util';
import { decodeAddress, encodeAddress, ethereumEncode } from '@polkadot/util-crypto';
@@ -147,8 +147,8 @@ class BaseIcon extends React.PureComponent<Props, State> {
}
}
function Identicon (props: Props): React.ReactElement<Props> {
function Icon (props: Props): React.ReactElement<Props> {
return <BaseIcon {...props} />;
}
export default React.memo(Identicon);
export const Identicon = React.memo(Icon);
@@ -7,7 +7,7 @@ import React, { useCallback } from 'react';
import { beachballIcon } from '@polkadot/ui-shared';
function Beachball ({ address, className = '', size, style }: Props): React.ReactElement<Props> {
function Identicon ({ address, className = '', size, style }: Props): React.ReactElement<Props> {
const updateElem = useCallback(
(node: HTMLDivElement): void => {
node && node.appendChild(
@@ -26,4 +26,4 @@ function Beachball ({ address, className = '', size, style }: Props): React.Reac
);
}
export default React.memo(Beachball);
export const Beachball = React.memo(Identicon);
+2 -2
View File
@@ -5,7 +5,7 @@ import type { Props } from '../types';
import React from 'react';
function Empty ({ className = '', size, style }: Props): React.ReactElement<Props> {
function Identicon ({ className = '', size, style }: Props): React.ReactElement<Props> {
return (
<svg
className={className}
@@ -17,4 +17,4 @@ function Empty ({ className = '', size, style }: Props): React.ReactElement<Prop
);
}
export default React.memo(Empty);
export const Empty = React.memo(Identicon);
@@ -7,7 +7,7 @@ import makeBlockie from 'ethereum-blockies-base64';
import React, { useMemo } from 'react';
import styled from 'styled-components';
function Ethereum ({ address, className = '', style }: Props): React.ReactElement<Props> {
function Identicon ({ address, className = '', style }: Props): React.ReactElement<Props> {
const imgSrc = useMemo(
() => makeBlockie(address),
[address]
@@ -22,7 +22,7 @@ function Ethereum ({ address, className = '', style }: Props): React.ReactElemen
);
}
export default React.memo(styled(Ethereum)(({ size }: Props) => `
export const Ethereum = React.memo(styled(Identicon)(({ size }: Props) => `
display: block;
height: ${size}px;
width: ${size}px;
@@ -6,7 +6,7 @@ import type { Props } from '../types';
import jdenticon from 'jdenticon';
import React from 'react';
function Jdenticon ({ className = '', publicKey, size, style }: Props): React.ReactElement<Props> {
function Identicon ({ className = '', publicKey, size, style }: Props): React.ReactElement<Props> {
return (
<div
className={className}
@@ -18,4 +18,4 @@ function Jdenticon ({ className = '', publicKey, size, style }: Props): React.Re
);
}
export default React.memo(Jdenticon);
export const Jdenticon = React.memo(Identicon);
@@ -51,4 +51,4 @@ function Identicon ({ address, className = '', isAlternative = false, size, styl
);
}
export default React.memo(Identicon);
export const Polkadot = React.memo(Identicon);
+5 -5
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2020 @polkadot/react-identicon authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { default as Beachball } from './Beachball';
export { default as Empty } from './Empty';
export { default as Ethereum } from './Ethereum';
export { default as Jdenticon } from './Jdenticon';
export { default as Polkadot } from './Polkadot';
export { Beachball } from './Beachball';
export { Empty } from './Empty';
export { Ethereum } from './Ethereum';
export { Jdenticon } from './Jdenticon';
export { Polkadot } from './Polkadot';
+3 -1
View File
@@ -1,8 +1,10 @@
// Copyright 2017-2020 @polkadot/react-identicon authors & contributors
// SPDX-License-Identifier: Apache-2.0
import Identicon from './Identicon';
import { Identicon } from './Identicon';
export * from './icons';
export { Identicon };
export default Identicon;
+2 -2
View File
@@ -6,7 +6,7 @@ import styled from 'styled-components';
import { xxhashAsHex } from '@polkadot/util-crypto';
import qrcode from './qrcode';
import { qrcode } from './qrcode';
import { createFrames, createImgSize } from './util';
interface Props {
@@ -131,7 +131,7 @@ function Display ({ className, size, skipEncoding, style, value }: Props): React
);
}
export default React.memo(styled(Display)`
export const QrDisplay = React.memo(styled(Display)`
.ui--qr-Display {
height: 100%;
width: 100%;
+3 -3
View File
@@ -3,7 +3,7 @@
import React, { useMemo } from 'react';
import QrDisplay from './Display';
import { QrDisplay } from './Display';
import { createAddressPayload } from './util';
interface Props {
@@ -14,7 +14,7 @@ interface Props {
style?: React.CSSProperties;
}
function DisplayExtrinsic ({ address, className, genesisHash, size, style }: Props): React.ReactElement<Props> | null {
function DisplayAddress ({ address, className, genesisHash, size, style }: Props): React.ReactElement<Props> | null {
const data = useMemo(
() => createAddressPayload(address, genesisHash),
[address, genesisHash]
@@ -35,4 +35,4 @@ function DisplayExtrinsic ({ address, className, genesisHash, size, style }: Pro
);
}
export default React.memo(DisplayExtrinsic);
export const QrDisplayAddress = React.memo(DisplayAddress);
+2 -2
View File
@@ -3,7 +3,7 @@
import React, { useMemo } from 'react';
import QrDisplay from './Display';
import { QrDisplay } from './Display';
import { createSignPayload } from './util';
interface Props {
@@ -36,4 +36,4 @@ function DisplayPayload ({ address, className, cmd, genesisHash, payload, size,
);
}
export default React.memo(DisplayPayload);
export const QrDisplayPayload = React.memo(DisplayPayload);
+2 -2
View File
@@ -5,7 +5,7 @@ import React, { useMemo } from 'react';
import { NetworkSpecsStruct } from '@polkadot/ui-settings';
import QrDisplay from './Display';
import { QrDisplay } from './Display';
import { encodeString } from './util';
interface Props {
@@ -36,4 +36,4 @@ function DisplayNetworkSpecs ({ className, networkSpecs, size, style }: Props):
);
}
export default React.memo(DisplayNetworkSpecs);
export const QrNetworkSpecs = React.memo(DisplayNetworkSpecs);
+1 -1
View File
@@ -54,7 +54,7 @@ function Scan ({ className, delay = DEFAULT_DELAY, onError = DEFAULT_ERROR, onSc
);
}
export default React.memo(styled(Scan)`
export const QrScan = React.memo(styled(Scan)`
.ui--qr-Scan {
display: inline-block;
height: 100%;
+2 -2
View File
@@ -7,7 +7,7 @@ import { assert } from '@polkadot/util';
import { decodeAddress } from '@polkadot/util-crypto';
import { ADDRESS_PREFIX, SEED_PREFIX } from './constants';
import QrScan from './Scan';
import { QrScan } from './Scan';
interface ScanType {
isAddress: boolean;
@@ -60,4 +60,4 @@ function ScanAddress ({ className, onError, onScan, size, style }: Props): React
);
}
export default React.memo(ScanAddress);
export const QrScanAddress = React.memo(ScanAddress);
+2 -2
View File
@@ -3,7 +3,7 @@
import React, { useCallback } from 'react';
import QrScan from './Scan';
import { QrScan } from './Scan';
interface ScanType {
signature: string;
@@ -34,4 +34,4 @@ function ScanSignature ({ className, onError, onScan, size, style }: Props): Rea
);
}
export default React.memo(ScanSignature);
export const QrScanSignature = React.memo(ScanSignature);
+5 -5
View File
@@ -1,8 +1,8 @@
// Copyright 2017-2020 @polkadot/react-qr authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { default as QrDisplayAddress } from './DisplayAddress';
export { default as QrDisplayPayload } from './DisplayPayload';
export { default as QrScanAddress } from './ScanAddress';
export { default as QrScanSignature } from './ScanSignature';
export { default as QrNetworkSpecs } from './NetworkSpecs';
export { QrDisplayAddress } from './DisplayAddress';
export { QrDisplayPayload } from './DisplayPayload';
export { QrScanAddress } from './ScanAddress';
export { QrScanSignature } from './ScanSignature';
export { QrNetworkSpecs } from './NetworkSpecs';
+1 -1
View File
@@ -12,4 +12,4 @@ const qrcode: typeof _qrcode = _qrcode;
(qrcode as any).stringToBytes = (data: Uint8Array): Uint8Array =>
data;
export default qrcode;
export { qrcode };
+1 -1
View File
@@ -19,7 +19,7 @@
"store": "^2.0.12"
},
"devDependencies": {
"@polkadot/types": "^2.10.1",
"@polkadot/types": "^2.10.2-4",
"@types/mkdirp": "^1.0.1",
"@types/store": "^2.0.2"
},
+6 -6
View File
@@ -9,13 +9,13 @@ import type { KeyringOptions, KeyringStore } from './types';
import { createTestKeyring } from '@polkadot/keyring/testing';
import { isBoolean, isString } from '@polkadot/util';
import accounts from './observable/accounts';
import addresses from './observable/addresses';
import contracts from './observable/contracts';
import env from './observable/development';
import BrowserStore from './stores/Browser'; // direct import (skip index with all)
import { accounts } from './observable/accounts';
import { addresses } from './observable/addresses';
import { contracts } from './observable/contracts';
import { env } from './observable/env';
import { BrowserStore } from './stores/Browser'; // direct import (skip index with all)
export default class Base {
export class Base {
#accounts: AddressSubject;
#addresses: AddressSubject;
+4 -4
View File
@@ -9,12 +9,12 @@ import type { CreateResult, KeyringAddress, KeyringAddressType, KeyringItemType,
import BN from 'bn.js';
import { createPair } from '@polkadot/keyring/pair';
import chains from '@polkadot/ui-settings/defaults/chains';
import { chains } from '@polkadot/ui-settings/defaults/chains';
import { bnToBn, hexToU8a, isHex, isString, u8aSorted } from '@polkadot/util';
import { base64Decode, createKeyMulti } from '@polkadot/util-crypto';
import env from './observable/development';
import Base from './Base';
import { env } from './observable/env';
import { Base } from './Base';
import { accountKey, accountRegex, addressKey, addressRegex, contractKey, contractRegex } from './defaults';
import { KeyringOption } from './options';
@@ -122,7 +122,7 @@ export class Keyring extends Base implements KeyringStruct {
return Object
.keys(available)
.map((address): KeyringAddress => this.getAddress(address, 'account') as KeyringAddress)
.filter((account): boolean => env.isDevelopment() || account.meta.isTesting !== true);
.filter((account) => env.isDevelopment() || account.meta.isTesting !== true);
}
public getAddress (_address: string | Uint8Array, type: KeyringItemType | null = null): KeyringAddress | undefined {
+3 -3
View File
@@ -5,10 +5,10 @@ import './detectPackage';
import { Keyring } from './Keyring';
export { default as Ledger } from '@polkadot/ledger';
export { Ledger } from '@polkadot/ledger';
const keyring = new Keyring();
export default keyring;
export { Keyring, keyring };
export { Keyring };
export default keyring;
@@ -2,6 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
import { accountKey } from '../defaults';
import genericSubject from './genericSubject';
import { genericSubject } from './genericSubject';
export default genericSubject(accountKey, true);
export const accounts = genericSubject(accountKey, true);
@@ -2,6 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
import { addressKey } from '../defaults';
import genericSubject from './genericSubject';
import { genericSubject } from './genericSubject';
export default genericSubject(addressKey);
export const addresses = genericSubject(addressKey);
@@ -2,6 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
import { contractKey } from '../defaults';
import genericSubject from './genericSubject';
import { genericSubject } from './genericSubject';
export default genericSubject(contractKey);
export const contracts = genericSubject(contractKey);
@@ -5,7 +5,7 @@ import { BehaviorSubject } from 'rxjs';
const subject = new BehaviorSubject(false);
export default {
export const env = {
isDevelopment: (): boolean =>
subject.getValue(),
set: (isDevelopment: boolean): void => {
@@ -7,11 +7,11 @@ import type { AddressSubject, SingleAddress, SubjectInfo } from './types';
import { BehaviorSubject } from 'rxjs';
import createOptionItem from '../options/item';
import development from './development';
import { createOptionItem } from '../options/item';
import { env } from './env';
function callNext (current: SubjectInfo, subject: BehaviorSubject<SubjectInfo>, withTest: boolean): void {
const isDevMode = development.isDevelopment();
const isDevMode = env.isDevelopment();
const filtered: SubjectInfo = {};
Object.keys(current).forEach((key): void => {
@@ -25,12 +25,12 @@ function callNext (current: SubjectInfo, subject: BehaviorSubject<SubjectInfo>,
subject.next(filtered);
}
export default function genericSubject (keyCreator: (address: string) => string, withTest = false): AddressSubject {
export function genericSubject (keyCreator: (address: string) => string, withTest = false): AddressSubject {
let current: SubjectInfo = {};
const subject = new BehaviorSubject({});
const next = (): void => callNext(current, subject, withTest);
development.subject.subscribe(next);
env.subject.subscribe(next);
return {
add: (store: KeyringStore, address: string, json: KeyringJson, type?: KeypairType): SingleAddress => {
@@ -43,7 +43,7 @@ export default function genericSubject (keyCreator: (address: string) => string,
};
// we do not store dev accounts, injected or hardware (the latter two are external/transient)
if (!json.meta.isInjected && !json.meta.isHardware && (!json.meta.isTesting || development.isDevelopment())) {
if (!json.meta.isInjected && !json.meta.isHardware && (!json.meta.isTesting || env.isDevelopment())) {
store.set(keyCreator(address), json);
}
+4 -4
View File
@@ -6,9 +6,9 @@ import type { SubjectInfo } from './types';
import { combineLatest } from 'rxjs';
import { map } from 'rxjs/operators';
import accounts from './accounts';
import addresses from './addresses';
import contracts from './contracts';
import { accounts } from './accounts';
import { addresses } from './addresses';
import { contracts } from './contracts';
interface Result {
accounts: SubjectInfo;
@@ -16,7 +16,7 @@ interface Result {
contracts: SubjectInfo;
}
export default combineLatest(
export const obervableAll = combineLatest(
accounts.subject,
addresses.subject,
contracts.subject
+2 -2
View File
@@ -9,7 +9,7 @@ import { BehaviorSubject } from 'rxjs';
import { assert } from '@polkadot/util';
import observableAll from '../observable';
import { obervableAll } from '../observable';
let hasCalledInitOptions = false;
@@ -49,7 +49,7 @@ export class KeyringOption implements KeyringOptionInstance {
public init (keyring: KeyringStruct): void {
assert(!hasCalledInitOptions, 'Unable to initialise options more than once');
observableAll.subscribe((): void => {
obervableAll.subscribe((): void => {
const opts = this.emptyOptions();
this.addAccounts(keyring, opts);
+1 -1
View File
@@ -5,7 +5,7 @@ import type { KeyringSectionOption } from './types';
import { isUndefined } from '@polkadot/util';
export default function createItem (address: string, _name?: string): KeyringSectionOption {
export function createOptionItem (address: string, _name?: string): KeyringSectionOption {
const name = isUndefined(_name)
? (
(address.length > 15)
+1 -1
View File
@@ -5,7 +5,7 @@ import type { KeyringJson, KeyringStore } from '../types';
import store from 'store';
export default class BrowserStore implements KeyringStore {
export class BrowserStore implements KeyringStore {
public all (cb: (key: string, value: KeyringJson) => void): void {
store.each((value: KeyringJson, key: string): void => {
cb(key, value);
+1 -1
View File
@@ -10,7 +10,7 @@ import path from 'path';
import { assert } from '@polkadot/util';
// NOTE untested and unused by any known apps, probably broken in various mysterious ways
export default class FileStore implements KeyringStore {
export class FileStore implements KeyringStore {
#path: string;
constructor (path: string) {
+2 -2
View File
@@ -1,5 +1,5 @@
// Copyright 2017-2020 @polkadot/ui-keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { default as BrowserStore } from './Browser';
export { default as FileStore } from './File';
export { BrowserStore } from './Browser';
export { FileStore } from './File';
+1 -3
View File
@@ -170,6 +170,4 @@ export class Settings implements SettingsStruct {
}
}
const settings = new Settings();
export default settings;
export const settings = new Settings();
+1 -1
View File
@@ -9,4 +9,4 @@ const chains: Record <string, ChainDef> = known
.filter(({ genesisHash }) => genesisHash.length > 1)
.reduce((chains, { genesisHash, network }) => ({ ...chains, [network]: genesisHash }), {});
export default chains;
export { chains };
+3 -5
View File
@@ -1,13 +1,11 @@
// Copyright 2017-2020 @polkadot/ui-settings authors & contributors
// SPDX-License-Identifier: Apache-2.0
import settings, { Settings } from './Settings';
import { Settings, settings } from './Settings';
export { ENDPOINT_DEFAULT, ICON_DEFAULT, ICON_DEFAULT_HOST, LANGUAGE_DEFAULT, LOCKING_DEFAULT, PREFIX_DEFAULT, UIMODE_DEFAULT, UITHEME_DEFAULT } from './defaults';
export { SettingsStruct, NetworkSpecsStruct } from './types';
export default settings;
export { settings, Settings };
export {
Settings
};
export default settings;
@@ -3,8 +3,8 @@
import type { ColorGen } from './types';
import newColors from './colors';
import newSeeder from './seeder';
import { colors as newColors } from './colors';
import { seeder as newSeeder } from './seeder';
describe('colors', (): void => {
let colors: ColorGen;
@@ -11,7 +11,7 @@ import { COLORS } from './defaults';
const WOBBLE = 30;
export default function colors (seeder: Seeder): ColorGen {
export function colors (seeder: Seeder): ColorGen {
const amount = (seeder() * WOBBLE) - (WOBBLE / 2);
const all = COLORS.map((hex): Color =>
Color(hex).rotate(amount)
@@ -1,7 +1,7 @@
// Copyright 2017-2020 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0
import container from './container';
import { container } from './container';
describe('container', (): void => {
it('applies default styles', (): void => {
@@ -3,7 +3,7 @@
// Copyright 2016 Dan Finlay
export default function container (diameter: number, background = 'white', className = '', _style: { [index: string]: string } = {}): HTMLElement {
export function container (diameter: number, background = 'white', className = '', _style: { [index: string]: string } = {}): HTMLElement {
const element = document.createElement('div');
const style = Object.assign({
background,
@@ -6,7 +6,7 @@
import { isNull } from '@polkadot/util';
import { encodeAddress, randomAsU8a } from '@polkadot/util-crypto';
import identicon from '.';
import { beachballIcon } from '.';
const element = document.getElementById('demo');
@@ -18,7 +18,7 @@ function generateIcon (seed: string = encodeAddress(randomAsU8a(32))): void {
}
element.appendChild(
identicon(seed, { isAlternative: false, size: 100 }, 'padded')
beachballIcon(seed, { isAlternative: false, size: 100 }, 'padded')
);
console.log(`Icon generated in ${(Date.now() - start)}ms`);
@@ -3,13 +3,13 @@
import xmlserializer from 'xmlserializer';
import generate from '.';
import { beachballIcon } from '.';
describe('identicon', (): void => {
it('generates a basic [0,..,0] identicon', (): void => {
expect(
xmlserializer.serializeToString(
generate(new Uint8Array(32), { isAlternative: false, size: 256 })
beachballIcon(new Uint8Array(32), { isAlternative: false, size: 256 })
)
).toEqual(
'<div xmlns="http://www.w3.org/1999/xhtml" class="" style="background: white; border-radius: 128px; display: inline-block; height: 256px; margin: 0px; overflow: hidden; padding: 0px; width: 256px;"><div class="" style="background: rgb(20, 20, 20); border-radius: 128px; display: inline-block; height: 256px; margin: 0px; overflow: hidden; padding: 0px; width: 256px;"><svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="256" height="256"><circle cx="128" cy="140.8" r="128" fill="hsl(212.10000000000002, 65.6%, 55.5%)"/><circle cx="128" cy="153.6" r="102.4" fill="hsl(9.800000000000011, 90.7%, 57.6%)"/><circle cx="128" cy="166.4" r="76.8" fill="hsl(345, 85.7%, 86.3%)"/><circle cx="128" cy="179.2" r="51.2" fill="hsl(261.9, 100%, 87.3%)"/><circle cx="128" cy="192" r="25.6" fill="hsl(345, 100%, 25.1%)"/></svg></div></div>'
@@ -19,7 +19,7 @@ describe('identicon', (): void => {
it('allows overrides', (): void => {
expect(
xmlserializer.serializeToString(
generate(new Uint8Array(32), { isAlternative: false, size: 100 }, 'testClass', { display: 'block' })
beachballIcon(new Uint8Array(32), { isAlternative: false, size: 100 }, 'testClass', { display: 'block' })
)
).toEqual(
'<div xmlns="http://www.w3.org/1999/xhtml" class="testClass" style="background: white; border-radius: 50px; display: block; height: 100px; margin: 0px; overflow: hidden; padding: 0px; width: 100px;"><div class="" style="background: rgb(20, 20, 20); border-radius: 50px; display: inline-block; height: 100px; margin: 0px; overflow: hidden; padding: 0px; width: 100px;"><svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="100" height="100"><circle cx="50" cy="55" r="50" fill="hsl(212.10000000000002, 65.6%, 55.5%)"/><circle cx="50" cy="60" r="40" fill="hsl(9.800000000000011, 90.7%, 57.6%)"/><circle cx="50" cy="65" r="30" fill="hsl(345, 85.7%, 86.3%)"/><circle cx="50" cy="70" r="20" fill="hsl(261.9, 100%, 87.3%)"/><circle cx="50" cy="75" r="10" fill="hsl(345, 100%, 25.1%)"/></svg></div></div>'
@@ -5,26 +5,26 @@
import type { Options } from '../types';
import newShape from './shape/circle';
import newElement from './svg/element';
import colors from './colors';
import newContainer from './container';
import { circle } from './shape/circle';
import { element } from './svg/element';
import { colors } from './colors';
import { container as newContainer } from './container';
import { SHAPE_COUNT } from './defaults';
import newSeeder from './seeder';
import { seeder as newSeeder } from './seeder';
export default function generate (seed: string | Uint8Array, { size = 256 }: Options, className = '', style?: { [index: string]: string }): HTMLElement {
export function beachballIcon (seed: string | Uint8Array, { size = 256 }: Options, className = '', style?: { [index: string]: string }): HTMLElement {
const seeder = newSeeder(seed);
const colorGen = colors(seeder);
const outer = newContainer(size, 'white', className, style);
const container = newContainer(size, colorGen());
const svg = newElement(size);
const svg = element(size);
outer.appendChild(container);
container.appendChild(svg);
for (let count = 0; count < SHAPE_COUNT; count++) {
const fill = colorGen();
const shape = newShape(seeder, fill, size, count);
const shape = circle(seeder, fill, size, count);
svg.appendChild(shape);
}
@@ -3,7 +3,7 @@
import type { Seeder } from './types';
import newSeeder from './seeder';
import { seeder as newSeeder } from './seeder';
describe('seeder', (): void => {
let seeder: Seeder;
@@ -7,7 +7,7 @@ import { isU8a, stringToU8a } from '@polkadot/util';
const DIVISOR = 256 * 256;
export default function seeder (_seed: string | Uint8Array = new Uint8Array(32)): Seeder {
export function seeder (_seed: string | Uint8Array = new Uint8Array(32)): Seeder {
const seed: Uint8Array = isU8a(_seed)
? _seed
: stringToU8a(_seed);
@@ -3,8 +3,8 @@
import xmlserializer from 'xmlserializer';
import seeder from '../seeder';
import circle from './circle';
import { seeder } from '../seeder';
import { circle } from './circle';
describe('circle', (): void => {
it('creates a circle shape', (): void => {
@@ -6,9 +6,9 @@
import type { Seeder } from '../types';
import { SHAPE_COUNT } from '../defaults';
import newCircle from '../svg/circle';
import { circle as newCircle } from '../svg/circle';
export default function circle (seeder: Seeder, fill: string, diameter: number, count: number): Element {
export function circle (seeder: Seeder, fill: string, diameter: number, count: number): Element {
const center = diameter / 2;
const angle = seeder() * 360;
const radius = (((SHAPE_COUNT - count) / SHAPE_COUNT) * (diameter / 2)) + ((diameter / 8) * seeder());
@@ -6,9 +6,9 @@
import type { Seeder } from '../types';
import { SHAPE_COUNT } from '../defaults';
import newRect from '../svg/rect';
import { rect as newRect } from '../svg/rect';
export default function square (seeder: Seeder, fill: string, diameter: number, count: number): Element {
export function square (seeder: Seeder, fill: string, diameter: number, count: number): Element {
const center = diameter / 2;
const svg = newRect(diameter);
const firstRot = seeder();
@@ -1,14 +1,14 @@
// Copyright 2017-2020 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0
import xmlserializer from 'xmlserializer';
import { serializeToString } from 'xmlserializer';
import circle from './circle';
import { circle } from './circle';
describe('circle', (): void => {
it('creates a basic SVG circle element', (): void => {
expect(
xmlserializer.serializeToString(
serializeToString(
circle(123, 12, 34)
)
).toEqual('<circle xmlns="http://www.w3.org/2000/svg" cx="12" cy="34" r="123"/>');
@@ -1,10 +1,10 @@
// Copyright 2017-2020 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0
import createSvg from './svg';
import { svg } from './svg';
export default function circle (r: number, cx: number, cy: number): Element {
const elem = createSvg('circle');
export function circle (r: number, cx: number, cy: number): Element {
const elem = svg('circle');
elem.setAttributeNS('', 'cx', `${cx}`);
elem.setAttributeNS('', 'cy', `${cy}`);
@@ -1,14 +1,14 @@
// Copyright 2017-2020 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0
import xmlserializer from 'xmlserializer';
import { serializeToString } from 'xmlserializer';
import element from './element';
import { element } from './element';
describe('element', (): void => {
it('creates a basic SVG element', (): void => {
expect(
xmlserializer.serializeToString(
serializeToString(
element(123)
)
).toEqual('<svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="123" height="123"/>');
@@ -3,10 +3,10 @@
// Copyright 2016 Dan Finlay
import createSvg from './svg';
import { svg } from './svg';
export default function element (size: number, type = 'svg', x = 0, y = 0): Element {
const elem = createSvg(type);
export function element (size: number, type = 'svg', x = 0, y = 0): Element {
const elem = svg(type);
elem.setAttributeNS('', 'x', `${x}`);
elem.setAttributeNS('', 'y', `${y}`);
@@ -1,14 +1,14 @@
// Copyright 2017-2020 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0
import xmlserializer from 'xmlserializer';
import { serializeToString } from 'xmlserializer';
import rect from './rect';
import { rect } from './rect';
describe('rect', (): void => {
it('creates a basic SVG rect element', (): void => {
expect(
xmlserializer.serializeToString(
serializeToString(
rect(123)
)
).toEqual('<rect xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="123" height="123" rx="7.6875" ry="7.6875"/>');
@@ -1,10 +1,10 @@
// Copyright 2017-2020 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0
import createElement from './element';
import { element } from './element';
export default function rect (size: number): Element {
const elem = createElement(size, 'rect');
export function rect (size: number): Element {
const elem = element(size, 'rect');
elem.setAttributeNS('', 'rx', `${size / 16}`);
elem.setAttributeNS('', 'ry', `${size / 16}`);
@@ -1,14 +1,14 @@
// Copyright 2017-2020 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0
import xmlserializer from 'xmlserializer';
import { serializeToString } from 'xmlserializer';
import svg from './svg';
import { svg } from './svg';
describe('svg', (): void => {
it('creates a basic SVG element', (): void => {
expect(
xmlserializer.serializeToString(
serializeToString(
svg('rect')
)
).toEqual('<rect xmlns="http://www.w3.org/2000/svg"/>');
@@ -5,6 +5,6 @@
const SVG_NS = 'http://www.w3.org/2000/svg';
export default function svg (type: string): Element {
export function svg (type: string): Element {
return document.createElementNS(SVG_NS, type);
}
+2 -2
View File
@@ -1,5 +1,5 @@
// Copyright 2018-2020 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { default as beachballIcon } from './beachball';
export { default as polkadotIcon } from './polkadot';
export { beachballIcon } from './beachball';
export { polkadotIcon } from './polkadot';
@@ -1,12 +1,12 @@
// Copyright 2018-2020 @polkadot/ui-shared authors & contributors
// SPDX-License-Identifier: Apache-2.0
import generate from './polkadot';
import { polkadotIcon } from './polkadot';
describe('polkadotIcon', (): void => {
it('generates the correct points from known', (): void => {
expect(
generate('5Dqvi1p4C7EhPPFKCixpF3QiaJEaDwWrR9gfWR5eUsfC39TX', { isAlternative: false })
polkadotIcon('5Dqvi1p4C7EhPPFKCixpF3QiaJEaDwWrR9gfWR5eUsfC39TX', { isAlternative: false })
).toEqual([
{ cx: 32, cy: 32, fill: '#eee', r: 32 },
{ cx: 32, cy: 8, fill: 'hsl(196, 65%, 53%)', r: 5 },
+1 -1
View File
@@ -131,7 +131,7 @@ function getColors (address: string): string[] {
/**
* @description Generate a array of the circles that make up an identicon
*/
export default function generate (address: string, { isAlternative }: Options): Circle[] {
export function polkadotIcon (address: string, { isAlternative }: Options): Circle[] {
const colors = getColors(address);
return [OUTER_CIRCLE].concat(
+23 -38
View File
@@ -2006,9 +2006,9 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/dev@npm:^0.60.12":
version: 0.60.12
resolution: "@polkadot/dev@npm:0.60.12"
"@polkadot/dev@npm:^0.60.13":
version: 0.60.13
resolution: "@polkadot/dev@npm:0.60.13"
dependencies:
"@babel/cli": ^7.12.8
"@babel/core": ^7.12.9
@@ -2095,7 +2095,7 @@ __metadata:
polkadot-exec-typedoc: scripts/polkadot-exec-typedoc.cjs
polkadot-exec-vuepress: scripts/polkadot-exec-vuepress.cjs
polkadot-exec-webpack: scripts/polkadot-exec-webpack.cjs
checksum: 13f7153ccc62fc62c4823946175845f8c6b50b1e20e9321ce607ea23a0b8b39f3359e707997a62ce31a44c6ea8b9a134b206e3aecd970ff9c3b040d3cd79f06e
checksum: 9df7ab2952be5d943ab5db9d04379f2f1b1f56e89c16843417952ad081b3f9c341a338549c8147751507654d51b80d6144e737a326ae17a0feba307ecae46ff3
languageName: node
linkType: hard
@@ -2157,17 +2157,17 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/metadata@npm:2.10.1":
version: 2.10.1
resolution: "@polkadot/metadata@npm:2.10.1"
"@polkadot/metadata@npm:2.10.2-4":
version: 2.10.2-4
resolution: "@polkadot/metadata@npm:2.10.2-4"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/types": 2.10.1
"@polkadot/types-known": 2.10.1
"@polkadot/types": 2.10.2-4
"@polkadot/types-known": 2.10.2-4
"@polkadot/util": ^4.2.1
"@polkadot/util-crypto": ^4.2.1
bn.js: ^4.11.9
checksum: 4d63d7ea0f54cc41435b0e2d4a0d0529cd62402314bae3f4a89b38a227bd4c24106df50282cc5077aa9021d1d08a05f5e9fe031ece7d2b0e8dfd1abc3c1d6ec2
checksum: 1e1462d81b5d311024dcd92b3dcb7d028d2a5439714c571db74ae83d914e2e292ab0c0c47f24988f924db8d01ec4607b3f30697805d0a749d610b9a2deb49787
languageName: node
linkType: hard
@@ -2258,31 +2258,31 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/types-known@npm:2.10.1":
version: 2.10.1
resolution: "@polkadot/types-known@npm:2.10.1"
"@polkadot/types-known@npm:2.10.2-4":
version: 2.10.2-4
resolution: "@polkadot/types-known@npm:2.10.2-4"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/types": 2.10.1
"@polkadot/types": 2.10.2-4
"@polkadot/util": ^4.2.1
bn.js: ^4.11.9
checksum: d8ade5bf38fe06358be3793bb8f3f9bb956060f447c43b3e3a817e2e89be04fe7b039a0588b98116e30ec40df500b9ffc45b0f3b5418a75f9127dcd94478e15e
checksum: e457f5a3895660d43d10316babc7564a4e3674f578418f62b655e4cc3ea38d0dde4db642baca932a2da67d78d2a942be05c8fa1c43875944093c523b3d4c512c
languageName: node
linkType: hard
"@polkadot/types@npm:2.10.1, @polkadot/types@npm:^2.10.1":
version: 2.10.1
resolution: "@polkadot/types@npm:2.10.1"
"@polkadot/types@npm:2.10.2-4, @polkadot/types@npm:^2.10.2-4":
version: 2.10.2-4
resolution: "@polkadot/types@npm:2.10.2-4"
dependencies:
"@babel/runtime": ^7.12.5
"@polkadot/metadata": 2.10.1
"@polkadot/metadata": 2.10.2-4
"@polkadot/util": ^4.2.1
"@polkadot/util-crypto": ^4.2.1
"@types/bn.js": ^4.11.6
bn.js: ^4.11.9
memoizee: ^0.4.14
rxjs: ^6.6.3
checksum: 912eb71dd35c0f007e4aeaba59b6da0aaa12785d3e5d44233ed45b40fe2fba897fc9d6f84eda902d6bca45e1b82361a1530a0c2a55150780b54be347d9677f3c
checksum: 5b0d75271c8f1d3887ce03e2836c124842b7a67959de1599f992a12d3d7a8284b6df8aca0aa7cc12713e87af4da547798151ba97996390ae2d2baff56a0908a9
languageName: node
linkType: hard
@@ -2301,7 +2301,7 @@ __metadata:
"@babel/runtime": ^7.12.5
"@polkadot/keyring": ^4.2.1
"@polkadot/ledger": ^0.62.2-22
"@polkadot/types": ^2.10.1
"@polkadot/types": ^2.10.2-4
"@polkadot/ui-settings": 0.62.2-22
"@polkadot/util": ^4.2.1
"@types/mkdirp": ^1.0.1
@@ -13897,7 +13897,7 @@ fsevents@~2.1.2:
dependencies:
"@babel/core": ^7.12.9
"@babel/runtime": ^7.12.5
"@polkadot/dev": ^0.60.12
"@polkadot/dev": ^0.60.13
"@polkadot/ts": ^0.3.57
"@types/jest": ^26.0.17
babel-plugin-transform-vue-template: ^0.4.2
@@ -16737,22 +16737,7 @@ fsevents@~2.1.2:
languageName: node
linkType: hard
"yargs@npm:^16.0.3":
version: 16.1.1
resolution: "yargs@npm:16.1.1"
dependencies:
cliui: ^7.0.2
escalade: ^3.1.1
get-caller-file: ^2.0.5
require-directory: ^2.1.1
string-width: ^4.2.0
y18n: ^5.0.5
yargs-parser: ^20.2.2
checksum: f88462770b6d65107b7295bdd68c38bc3cba9ab0362df476f44c5f6770ee2f39f48bca9813e8a9dc792a15f93e051a7e37346c0f66cf0ec35c63869963c43e0c
languageName: node
linkType: hard
"yargs@npm:^16.2.0":
"yargs@npm:^16.0.3, yargs@npm:^16.2.0":
version: 16.2.0
resolution: "yargs@npm:16.2.0"
dependencies: