-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤑Show basic transaction progress info (#51)
- Loading branch information
Kamil DÄ…browski
authored
Jan 30, 2020
1 parent
b75edaa
commit b6b21f8
Showing
9 changed files
with
253 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, {ReactNode} from 'react'; | ||
import styled from 'styled-components'; | ||
import {Spinner} from './Spinner'; | ||
|
||
export interface ModalProps { | ||
children: ReactNode; | ||
onClose: () => void; | ||
inProgress: boolean; | ||
} | ||
|
||
export const Modal = ({children, onClose, inProgress}: ModalProps) => | ||
(<ModalBackdrop className='modal-backdrop' data-testid='modal'> | ||
<ModalBody className={'modal-body'}> | ||
{inProgress | ||
? <Spinner/> | ||
: <CloseButton className='modal-close' onClick={onClose}/> | ||
} | ||
{children} | ||
</ModalBody> | ||
</ModalBackdrop>); | ||
|
||
const ModalBackdrop = styled.div` | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(12, 35, 64, 0.7); | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
z-index: 1000; | ||
`; | ||
|
||
const ModalBody = styled.div` | ||
position: relative; | ||
padding: 30px 40px; | ||
min-width: 400px; | ||
min-height: 200px; | ||
max-height: 95%; | ||
overflow-y: scroll; | ||
background-color: #FFFFFF; | ||
border-radius: 8px; | ||
box-shadow: 0 20px 50px -10px rgba(0, 0, 0, 0.2); | ||
`; | ||
|
||
const CloseButton = styled.div` | ||
position: absolute; | ||
top: 30px; | ||
right: 30px; | ||
width: 20px; | ||
height: 20px; | ||
&::before, &::after { | ||
content: ''; | ||
width: 17px; | ||
height: 2px; | ||
border-radius: 1px; | ||
display: block; | ||
background-color: #1c1c1c; | ||
transform: translate(-50%, -50%) rotate(45deg); | ||
position: absolute; | ||
top: 10px; | ||
left: 10px; | ||
} | ||
&::after { | ||
transform: translate(-50%, -50%) rotate(135deg); | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
export const Spinner = () => ( | ||
<Loader/> | ||
); | ||
|
||
const Loader = styled.div` | ||
position: absolute; | ||
top: 30px; | ||
right: 30px; | ||
width: 1.5rem; | ||
height: 1.5rem; | ||
margin: 1.5rem; | ||
border-radius: 50%; | ||
border: 0.3rem solid #181EA9; | ||
border-top-color: #FFFFFF; | ||
animation: 1.5s spin infinite linear; | ||
&.multi { | ||
border-bottom-color: #FFFFFF; | ||
} | ||
@keyframes spin { | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import {CTAButton} from './commons/CTAButton'; | ||
|
||
export const TransactionProgress = (props: { transactionHash: string | undefined, errorMessage: string | undefined }) => <> | ||
<Title>Transaction in progress</Title> | ||
<a href={`https://rinkeby.etherscan.io/address/${props.transactionHash && props.transactionHash}`} | ||
data-testid='etherscan-link'> | ||
<CTAButton data-testid='etherscan-button' | ||
disabled={props.errorMessage !== undefined || props.transactionHash === undefined}>View transaction | ||
details</CTAButton> | ||
</a> | ||
{props.errorMessage && <div data-testid='error-message'>{props.errorMessage}</div>} | ||
</>; | ||
|
||
const Title = styled.p` | ||
font-style: normal; | ||
font-weight: bold; | ||
font-size: 24px; | ||
line-height: 29px; | ||
color: #181EA9; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const CTAButton = styled.button` | ||
background-color: #181EA9; | ||
border: none; | ||
color: white; | ||
padding: 15px 32px; | ||
margin: 12px 0; | ||
text-align: center; | ||
text-decoration: none; | ||
display: inline-block; | ||
font-size: 16px; | ||
border-radius: 8px; | ||
&:disabled { | ||
opacity: 0.3; | ||
background: grey; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {useCallback, useState} from 'react'; | ||
|
||
export const useModal = (initialMode = false): [boolean, () => void, () => void] => { | ||
const [isModalVisible, setIsModalVisible] = useState(initialMode); | ||
const closeModal = useCallback(() => setIsModalVisible(false), []); | ||
const openModal = useCallback(() => setIsModalVisible(true), []); | ||
|
||
return [isModalVisible, openModal, closeModal]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React from 'react'; | ||
import {fireEvent, render, wait, waitForElement} from '@testing-library/react'; | ||
import {createMockProvider} from 'ethereum-waffle'; | ||
import {Account} from '../src/ui/Account'; | ||
import {ServiceContext} from '../src/ui/useServices'; | ||
import {Services} from '../src/services'; | ||
import chai, {expect} from 'chai'; | ||
import chaiDom from 'chai-dom'; | ||
import {createTestServices} from './helpers/testServices'; | ||
import {TransactionDenied} from '../src/errors'; | ||
import sinon from 'sinon'; | ||
import {SnackbarProvider} from '../src/ui/Snackbar/SnackbarProvider'; | ||
|
||
chai.use(chaiDom); | ||
|
||
async function renderAccount(services: Services) { | ||
return render( | ||
<ServiceContext.Provider value={services}> | ||
<SnackbarProvider> | ||
<Account/> | ||
</SnackbarProvider> | ||
</ServiceContext.Provider> | ||
); | ||
} | ||
|
||
describe('Account page', () => { | ||
|
||
let services: Services; | ||
|
||
beforeEach(async () => { | ||
services = await createTestServices(createMockProvider()); | ||
}); | ||
|
||
it('shows balances', async () => { | ||
const {getByTestId} = await renderAccount(services); | ||
|
||
expect(await waitForElement(() => getByTestId('ETH-balance'))).to.have.text('9999999999999999.9721'); | ||
expect(await waitForElement(() => getByTestId('GNT-balance'))).to.have.text('140000000.000'); | ||
expect(await waitForElement(() => getByTestId('NGNT-balance'))).to.have.text('0.000'); | ||
expect(await waitForElement(() => getByTestId('GNTB-balance'))).to.have.text('9999900.000'); | ||
expect(await waitForElement(() => getByTestId('deposit'))).to.have.text('100.000'); | ||
}); | ||
|
||
it('shows migrated tokens', async () => { | ||
const {getByTestId} = await renderAccount(services); | ||
|
||
fireEvent.click(getByTestId('button')); | ||
|
||
await wait(() => { | ||
expect(getByTestId('NGNT-balance')).to.have.text('140000000.000'); | ||
expect(getByTestId('GNT-balance')).to.have.text('0.000'); | ||
}); | ||
}); | ||
|
||
it('shows modal on migrate', async () => { | ||
const {getByTestId} = await renderAccount(services); | ||
|
||
fireEvent.click(getByTestId('button')); | ||
|
||
await wait(() => { | ||
expect(getByTestId('modal')).to.exist; | ||
expect(getByTestId('etherscan-button')).to.have.text('View transaction details'); | ||
expect(getByTestId('etherscan-button')).to.not.have.attr('disabled'); | ||
expect(getByTestId('etherscan-link')).to.have.attr('href').match(/https:\/\/rinkeby.etherscan.io\/address\/0x[0-9a-fA-F]{64}/); | ||
}); | ||
}); | ||
|
||
it('shows error in modal with when user denied transaction', async () => { | ||
sinon.stub(services.tokensService, 'migrateAllTokens').rejects(new TransactionDenied(new Error())); | ||
const {getByTestId} = await renderAccount(services); | ||
|
||
fireEvent.click(getByTestId('button')); | ||
|
||
await wait(() => { | ||
expect(getByTestId('modal')).to.exist; | ||
expect(getByTestId('etherscan-button')).to.have.attr('disabled'); | ||
expect(getByTestId('error-message')).to.have.text('User denied transaction signature.'); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.