Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attestation to claims #2734

Merged
merged 79 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
500558f
init
Tbaut May 13, 2020
f17564d
Attest component
Tbaut May 13, 2020
e2531ef
Add top notification bar
amaury1093 May 13, 2020
605164c
Merge branch 'tbaut-attest' of ssh://github.com/polkadot-js/apps into…
amaury1093 May 13, 2020
7d44d18
better english
amaury1093 May 13, 2020
5ac3558
back to 3 steps
Tbaut May 13, 2020
295a8a5
clean up
Tbaut May 13, 2020
4abc5df
in the middle of the refactoring
Tbaut May 13, 2020
eb9a3f2
Make TS pass
amaury1093 May 13, 2020
00c514d
Clea up some comments
amaury1093 May 13, 2020
6f983db
isPreclaimed
Tbaut May 13, 2020
ef7a173
isOldClaimProcess
Tbaut May 13, 2020
8420502
Attest vs Claim (#2737)
amaury1093 May 13, 2020
f011f10
fix flow between claim and attest (#2738)
amaury1093 May 13, 2020
5643a67
Jaco's comments + Fetch StatementKind (#2741)
amaury1093 May 13, 2020
9fa046d
Fix small bug in flow
amaury1093 May 13, 2020
63ab76c
Add condition for the warning banner (#2742)
Tbaut May 13, 2020
8d99149
fix CI
Tbaut May 13, 2020
94d496c
Add ETH address field for non preclaimed addresses (#2746)
Tbaut May 14, 2020
93a3466
Update packages/page-claims/src/index.tsx
amaury1093 May 14, 2020
52ae0ef
Update packages/page-claims/src/index.tsx
amaury1093 May 14, 2020
882b141
Update packages/apps/src/overlays/Attest.tsx
amaury1093 May 14, 2020
1a40a02
Show the amount of token that will be claimed (#2747)
Tbaut May 14, 2020
c5cf84b
Use counter instead of overlay (#2750)
amaury1093 May 14, 2020
29869d5
Update packages/page-claims/src/Warning.tsx
Tbaut May 14, 2020
f9128cc
Update packages/page-claims/src/index.tsx
Tbaut May 14, 2020
813a5f2
Update packages/page-claims/src/index.tsx
Tbaut May 14, 2020
28de108
Update packages/page-claims/src/index.tsx
Tbaut May 14, 2020
34fe9d1
Update packages/page-claims/src/index.tsx
Tbaut May 14, 2020
cadb81f
address comment shortcut
Tbaut May 14, 2020
64dfb3d
set Ethereum address outside transfor and fix typos
Tbaut May 14, 2020
c4c8cae
lint
Tbaut May 14, 2020
407cab2
extract claims.preclaims to a hook
Tbaut May 14, 2020
fb97c82
address comments EthereumAddress type and avoid casting
Tbaut May 14, 2020
df2f77f
Missing isUnsigned
amaury1093 May 15, 2020
e2920f9
use AddressMini in warning
Tbaut May 15, 2020
5dd8108
use a proper step for eth address field
Tbaut May 15, 2020
0f6ea73
Add loading state
amaury1093 May 15, 2020
3f16fea
remove log
amaury1093 May 15, 2020
5d35529
unwrapOrNull
amaury1093 May 15, 2020
6dba5b5
Update packages/page-claims/src/Warning.tsx
amaury1093 May 15, 2020
1d0e8fd
fix for account plural translation
Tbaut May 15, 2020
73d38e0
lint
Tbaut May 15, 2020
1d8a01e
Add getStatement function
amaury1093 May 18, 2020
8df104f
nits
amaury1093 May 18, 2020
19b8b3b
Fix lint
amaury1093 May 18, 2020
f62c962
Update packages/page-claims/src/Warning.tsx
amaury1093 May 18, 2020
875c367
add statement
Tbaut May 22, 2020
22873da
statement component
Tbaut May 22, 2020
4715412
address comment unWrapOr
Tbaut May 22, 2020
91f17de
test styling with long md
Tbaut May 22, 2020
95b847b
add md to jest
Tbaut May 22, 2020
bc65398
Update packages/page-claims/src/Statement.tsx
Tbaut May 22, 2020
20b79cf
copy text before
Tbaut May 22, 2020
de4e539
Merge branch 'tbaut-attest' of github.com:polkadot-js/apps into tbaut…
Tbaut May 22, 2020
4e05d28
lint
Tbaut May 22, 2020
5fd559e
Remove EthreumAddress type to avoid unexpected behaviors (#2796)
Tbaut May 22, 2020
c5ea7fa
Merge branch 'master' into tbaut-attest
amaury1093 May 22, 2020
fadf3db
Enhance UX for claim process (#2797)
Tbaut May 22, 2020
3c2a0f7
Add HTML components for statements (#2798)
amaury1093 May 22, 2020
8860ca2
Update to final statements
amaury1093 May 24, 2020
9f04541
More nits
amaury1093 May 24, 2020
8f12a36
Nits
amaury1093 May 24, 2020
f94b9d6
OnSuccess
amaury1093 May 24, 2020
5e09c6e
prevent display of empty statement when attested
Tbaut May 24, 2020
c1f2078
Merge branch 'master' into tbaut-attest
amaury1093 May 25, 2020
7d7995b
Small fixmes
amaury1093 May 25, 2020
e4377ba
Update packages/page-claims/src/index.tsx
amaury1093 May 25, 2020
1a7827e
fix isError not being red as expected
Tbaut May 25, 2020
0b2430d
remove word-break
Tbaut May 25, 2020
9d3b773
statement text in black
Tbaut May 25, 2020
f349265
attestation for -> accounc balance
Tbaut May 25, 2020
3c0a4c3
Update packages/page-claims/src/Statement.tsx
Tbaut May 25, 2020
1e14a20
margin left instead of space
Tbaut May 25, 2020
93b4777
I agree
Tbaut May 25, 2020
a800d9c
Use iframe
amaury1093 May 25, 2020
e5d7d60
update saft to QmXEkMahfhHJPzT3RjkXiZVFi77ZeVeuxtAjhojGRNYckz
Tbaut May 25, 2020
10cbbd2
Merge branch 'master' of github.com:polkadot-js/apps into tbaut-attest
Tbaut May 26, 2020
9698157
remove hash and duplications (#2814)
Tbaut May 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/apps/src/Apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useApi } from '@polkadot/react-hooks';
import Signer from '@polkadot/react-signer';

import AccountsOverlay from './overlays/Accounts';
import AttestOverlay from './overlays/Attest';
import ConnectingOverlay from './overlays/Connecting';
import { SideBarTransition, SIDEBAR_MENU_THRESHOLD } from './constants';
import Content from './Content';
Expand Down Expand Up @@ -93,6 +94,7 @@ function Apps ({ className }: Props): React.ReactElement<Props> {
</Signer>
<ConnectingOverlay />
<AccountsOverlay />
<AttestOverlay />
<div id={PORTAL_ID} />
</div>
<WarmUp />
Expand Down
48 changes: 48 additions & 0 deletions packages/apps/src/overlays/Attest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2017-2020 @polkadot/apps authors & contributors
jacogr marked this conversation as resolved.
Show resolved Hide resolved
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import React from 'react';
import { useApi, useAccounts, useCall } from '@polkadot/react-hooks';
import { Option } from '@polkadot/types';
import { EthereumAddress } from '@polkadot/types/interfaces';
import { Link } from 'react-router-dom';

import { useTranslation } from '../translate';
import BaseOverlay from './Base';

interface Props {
className?: string;
}

function Attest ({ className }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { allAccounts } = useAccounts();
const { api } = useApi();

// Find accounts that need attest. They are accounts that
// - already preclaimed,
// - didn't sign the attest yet.
// `claims.preclaims` returns Some() for these accounts.
const needAttest = useCall<[Option<EthereumAddress>]>(api.query.claims?.preclaims.multi, [allAccounts])?.filter((opt) => opt.isSome);

if (!needAttest?.length) {
return null;
}

return (
<BaseOverlay className={className}
icon='warning sign'
type='error'>
<div>
{t(
'{{number}} account {{need}} to sign the attest before receiving DOTs. Please sign the attest ',
{ replace: { need: needAttest.length === 1 ? 'needs' : 'need', number: needAttest.length } }
)}
<Link to='/claims'>{t('here.')}</Link>
</div>
</BaseOverlay>
);
}

export default React.memo(Attest);
110 changes: 110 additions & 0 deletions packages/page-claims/src/Attest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Copyright 2017-2020 @polkadot/app-claims authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import { Signer } from '@polkadot/api/types';
import { web3FromSource } from '@polkadot/extension-dapp';
import { KeyringPair } from '@polkadot/keyring/types';
import { Button, Card } from '@polkadot/react-components';
import keyring from '@polkadot/ui-keyring';
import { stringToHex, stringToU8a, u8aToHex } from '@polkadot/util';

import React, { useCallback, useEffect, useState } from 'react';
import styled from 'styled-components';

import { useTranslation } from './translate';

interface Props {
accountId: string;
className?: string;
data: string;
onNextStep: (signature: string) => void;
}

function Attest ({ accountId, className, data, onNextStep }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
// const [attestSignature, setAttestSignature] = useState<string | null>(null);
const [currentPair, setCurrentPair] = useState<KeyringPair | null>(null);
const [signer, setSigner] = useState<Signer | null >(null);

useEffect((): void => {
const isInjected = currentPair?.meta.isInjected || false;

// for injected, retrieve the signer
if (currentPair && isInjected) {
const { meta: { source } } = currentPair;

web3FromSource(source)
.catch((): null => null)
.then((injected): void => setSigner(
injected?.signer || null
));
}
}, [currentPair]);

useEffect(() => {
setCurrentPair(keyring.getPair(accountId || ''));
}, [accountId]);

const _signAttest = useCallback(
(): void => {
if (!currentPair) {
return;
}

if (signer?.signRaw) {
signer
.signRaw({
address: currentPair.address,
data: stringToHex(data),
type: 'bytes'
})
.then(({ signature }): void => onNextStep(signature));
} else {
onNextStep(u8aToHex(
currentPair.sign(stringToU8a(data))
));
}
},
[currentPair, data, onNextStep, signer]
);

return (
<Card className={className}>
<h3>{t('3. Sign attestation')}</h3>
<div>
{t('Clicking the following button will let you sign the hash of the attestation available at the following address: XXX')}
:
</div>
<Button.Group>
<Button
icon='sign-in'
isDisabled={!accountId}
label={t('Sign attestation')}
onClick={_signAttest}
/>
</Button.Group>

</Card>
);
}

export default React.memo(styled(Attest)`
/* font-size: 1.15rem;
display: flex;
flex-direction: column;
justify-content: center;
min-height: 12rem;
align-items: center;
margin: 0 1rem; */

h3 {
font-family: monospace;
font-size: 1.5rem;
max-width: 100%;
margin: 0.5rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
`);
Loading