Swap to polkadot-identicon (#207)
* Swap to polkadot-identicon * Delete index.spec.js * Delete index.spec.js
This commit is contained in:
parent
72794e83c5
commit
46af1e3497
@ -16,7 +16,8 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.0.0-beta.51",
|
||||
"@polkadot/ui-identicon": "^0.19.24"
|
||||
"@polkadot/ui-identicon": "^0.19.24",
|
||||
"polkadot-identicon": "^1.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/util-keyring": "^0.27.9",
|
||||
@ -33,8 +34,6 @@
|
||||
"style-loader": "^0.19.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.4.1",
|
||||
"react-router": "^4.3.1",
|
||||
"react-router-dom": "^4.3.1"
|
||||
"react": "^16.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
// Copyright 2017-2018 @polkadot/ui-react authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { shallow } from '../../test/enzyme';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { Container } from '../index';
|
||||
|
||||
describe('Container', () => {
|
||||
let wrapper;
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(
|
||||
<Container className='test' />,
|
||||
{}
|
||||
);
|
||||
});
|
||||
|
||||
it('creates the element', () => {
|
||||
expect(
|
||||
wrapper
|
||||
).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -1,26 +0,0 @@
|
||||
// Copyright 2017-2018 @polkadot/ui-react authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { shallow } from '../../test/enzyme';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { IdentityIcon } from '../index';
|
||||
|
||||
describe('IdentityIcon', () => {
|
||||
let wrapper;
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(
|
||||
<IdentityIcon className='test' />,
|
||||
{}
|
||||
);
|
||||
});
|
||||
|
||||
it('creates the element', () => {
|
||||
expect(
|
||||
wrapper
|
||||
).toBeDefined();
|
||||
});
|
||||
});
|
||||
@ -7,57 +7,30 @@ import { BaseProps } from '../types';
|
||||
import './IdentityIcon.css';
|
||||
|
||||
import React from 'react';
|
||||
import identicon from '@polkadot/ui-identicon/index';
|
||||
import encodeAddress from '@polkadot/util-keyring/address/encode';
|
||||
import isHex from '@polkadot/util/is/hex';
|
||||
import isU8a from '@polkadot/util/is/u8a';
|
||||
import Identicon from 'polkadot-identicon';
|
||||
|
||||
type Props = BaseProps & {
|
||||
size?: number,
|
||||
value: string | Uint8Array
|
||||
};
|
||||
|
||||
type State = {
|
||||
address: string
|
||||
};
|
||||
|
||||
const DEFAULT_SIZE = 64;
|
||||
|
||||
export default class IdentityIcon extends React.PureComponent<Props, State> {
|
||||
state: State = {} as State;
|
||||
|
||||
static getDerivedStateFromProps ({ value }: Props, prevState: State): State | null {
|
||||
const address = isU8a(value) || isHex(value)
|
||||
? encodeAddress(value)
|
||||
: value;
|
||||
|
||||
return address === prevState.address
|
||||
? null
|
||||
: { address };
|
||||
}
|
||||
|
||||
export default class IdentityIcon extends React.PureComponent<Props> {
|
||||
render () {
|
||||
const { className, style } = this.props;
|
||||
const { address } = this.state;
|
||||
const { className, size = DEFAULT_SIZE, style, value } = this.props;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={['ui--IdentityIcon', className].join(' ')}
|
||||
key={address}
|
||||
ref={this.appendIcon}
|
||||
key={value.toString()}
|
||||
style={style}
|
||||
/>
|
||||
>
|
||||
<Identicon
|
||||
id={value}
|
||||
size={size}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
private appendIcon = (node: Element | null): void => {
|
||||
const { size = DEFAULT_SIZE } = this.props;
|
||||
const { address } = this.state;
|
||||
|
||||
if (node) {
|
||||
node.appendChild(
|
||||
identicon(address, size)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
75
yarn.lock
75
yarn.lock
@ -2459,10 +2459,23 @@ binaryextensions@2:
|
||||
version "2.1.1"
|
||||
resolved "https://registry.yarnpkg.com/binaryextensions/-/binaryextensions-2.1.1.tgz#3209a51ca4a4ad541a3b8d3d6a6d5b83a2485935"
|
||||
|
||||
bindings@^1.2.1:
|
||||
version "1.3.0"
|
||||
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.3.0.tgz#b346f6ecf6a95f5a815c5839fc7cdb22502f1ed7"
|
||||
|
||||
bindings@~1.2.1:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.2.1.tgz#14ad6113812d2d37d72e67b4cacb4bb726505f11"
|
||||
|
||||
blake2js@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/blake2js/-/blake2js-1.0.0.tgz#b6890c394ddb9405d06d9a7ad3cf656711dcad89"
|
||||
dependencies:
|
||||
bindings "^1.2.1"
|
||||
debug "^2.2.0"
|
||||
nan "^2.4.0"
|
||||
readable-stream "^2.1.4"
|
||||
|
||||
blakejs@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/blakejs/-/blakejs-1.1.0.tgz#69df92ef953aa88ca51a32df6ab1c54a155fc7a5"
|
||||
@ -3560,6 +3573,14 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
|
||||
safe-buffer "^5.0.1"
|
||||
sha.js "^2.4.8"
|
||||
|
||||
create-react-class@^15.6.0:
|
||||
version "15.6.3"
|
||||
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.3.tgz#2d73237fb3f970ae6ebe011a9e66f46dbca80036"
|
||||
dependencies:
|
||||
fbjs "^0.8.9"
|
||||
loose-envify "^1.3.1"
|
||||
object-assign "^4.1.1"
|
||||
|
||||
cross-spawn@^5.0.1, cross-spawn@^5.1.0:
|
||||
version "5.1.0"
|
||||
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
|
||||
@ -4688,7 +4709,7 @@ fb-watchman@^2.0.0:
|
||||
dependencies:
|
||||
bser "^2.0.0"
|
||||
|
||||
fbjs@^0.8.16:
|
||||
fbjs@^0.8.16, fbjs@^0.8.9:
|
||||
version "0.8.17"
|
||||
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.17.tgz#c4d598ead6949112653d6588b01a5cdcd9f90fdd"
|
||||
dependencies:
|
||||
@ -7587,7 +7608,7 @@ mz@^2.6.0:
|
||||
object-assign "^4.0.1"
|
||||
thenify-all "^1.0.0"
|
||||
|
||||
nan@^2.0.7, nan@^2.3.3, nan@^2.8.0, nan@^2.9.2:
|
||||
nan@^2.0.7, nan@^2.3.3, nan@^2.4.0, nan@^2.8.0, nan@^2.9.2:
|
||||
version "2.10.0"
|
||||
resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f"
|
||||
|
||||
@ -7972,6 +7993,17 @@ only@~0.0.2:
|
||||
version "0.0.2"
|
||||
resolved "https://registry.yarnpkg.com/only/-/only-0.0.2.tgz#2afde84d03e50b9a8edc444e30610a70295edfb4"
|
||||
|
||||
oo7-react@^0.4.9:
|
||||
version "0.4.9"
|
||||
resolved "https://registry.yarnpkg.com/oo7-react/-/oo7-react-0.4.9.tgz#67160c1978add5063c7d0629a08494ae03667456"
|
||||
dependencies:
|
||||
oo7 "^0.5.9"
|
||||
react "^15.4.2"
|
||||
|
||||
oo7@^0.5.9:
|
||||
version "0.5.9"
|
||||
resolved "https://registry.yarnpkg.com/oo7/-/oo7-0.5.9.tgz#a4e948cab6ab9e1bf032c9ad588f4cbf31478b51"
|
||||
|
||||
open@0.0.5:
|
||||
version "0.0.5"
|
||||
resolved "https://registry.yarnpkg.com/open/-/open-0.0.5.tgz#42c3e18ec95466b6bf0dc42f3a2945c3f0cad8fc"
|
||||
@ -8326,6 +8358,15 @@ pn@^1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb"
|
||||
|
||||
polkadot-identicon@^1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/polkadot-identicon/-/polkadot-identicon-1.0.3.tgz#525aac828c352d979f4ae433bfba240ad7a099ca"
|
||||
dependencies:
|
||||
blake2js "^1.0.0"
|
||||
oo7-react "^0.4.9"
|
||||
react "^16.4.2"
|
||||
ss58 "^1.0.0"
|
||||
|
||||
posix-character-classes@^0.1.0:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
|
||||
@ -9036,7 +9077,7 @@ prompts@^0.1.9:
|
||||
kleur "^1.0.0"
|
||||
sisteransi "^0.1.1"
|
||||
|
||||
prop-types@^15.5.7, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2:
|
||||
prop-types@^15.5.10, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2:
|
||||
version "15.6.2"
|
||||
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102"
|
||||
dependencies:
|
||||
@ -9273,6 +9314,16 @@ react-test-renderer@^16.0.0-0:
|
||||
prop-types "^15.6.0"
|
||||
react-is "^16.4.1"
|
||||
|
||||
react@^15.4.2:
|
||||
version "15.6.2"
|
||||
resolved "https://registry.yarnpkg.com/react/-/react-15.6.2.tgz#dba0434ab439cfe82f108f0f511663908179aa72"
|
||||
dependencies:
|
||||
create-react-class "^15.6.0"
|
||||
fbjs "^0.8.9"
|
||||
loose-envify "^1.1.0"
|
||||
object-assign "^4.1.0"
|
||||
prop-types "^15.5.10"
|
||||
|
||||
react@^16.4.1:
|
||||
version "16.4.1"
|
||||
resolved "https://registry.yarnpkg.com/react/-/react-16.4.1.tgz#de51ba5764b5dbcd1f9079037b862bd26b82fe32"
|
||||
@ -9282,6 +9333,15 @@ react@^16.4.1:
|
||||
object-assign "^4.1.1"
|
||||
prop-types "^15.6.0"
|
||||
|
||||
react@^16.4.2:
|
||||
version "16.4.2"
|
||||
resolved "https://registry.yarnpkg.com/react/-/react-16.4.2.tgz#2cd90154e3a9d9dd8da2991149fdca3c260e129f"
|
||||
dependencies:
|
||||
fbjs "^0.8.16"
|
||||
loose-envify "^1.1.0"
|
||||
object-assign "^4.1.1"
|
||||
prop-types "^15.6.0"
|
||||
|
||||
read-cache@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/read-cache/-/read-cache-1.0.0.tgz#e664ef31161166c9751cdbe8dbcf86b5fb58f774"
|
||||
@ -9346,7 +9406,7 @@ read-pkg@^3.0.0:
|
||||
normalize-package-data "^2.3.2"
|
||||
path-type "^3.0.0"
|
||||
|
||||
"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.4, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.5, readable-stream@^2.3.6:
|
||||
"readable-stream@1 || 2", readable-stream@^2.0.0, readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.4, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@^2.3.3, readable-stream@^2.3.5, readable-stream@^2.3.6:
|
||||
version "2.3.6"
|
||||
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf"
|
||||
dependencies:
|
||||
@ -10212,6 +10272,13 @@ sprintf-js@~1.0.2:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
|
||||
|
||||
ss58@^1.0.0:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/ss58/-/ss58-1.0.2.tgz#e59f3482098c4b3d975ca6d359d1807441e07dfd"
|
||||
dependencies:
|
||||
blakejs "^1.1.0"
|
||||
bs58 "^4.0.1"
|
||||
|
||||
sshpk@^1.7.0:
|
||||
version "1.14.2"
|
||||
resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.14.2.tgz#c6fc61648a3d9c4e764fd3fcdf4ea105e492ba98"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user