Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
fix: reverse lockup timeout component
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed May 15, 2019
1 parent 70c70ec commit 5ec379d
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/__test__/unit/action/DataStorage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('data storage actions', () => {
type: actionTypes.SET_ASSET,
payload,
};
expect(actions.dataStorageSetAsset(payload.asset, payload.amount)).toEqual(
expect(actions.dataStorageSetAsset(payload, payload.amount)).toEqual(
expectedAction
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/actions/datastorageActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const dataStorageSetId = id => ({
* @param {String} asset
* @param {Number} amount
*/
export const dataStorageSetAsset = (asset, amount) => ({
export const dataStorageSetAsset = ({ asset, amount }) => ({
type: actionTypes.SET_ASSET,
payload: {
asset,
Expand Down
4 changes: 4 additions & 0 deletions src/actions/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class Navigation {
navReverseSwap = () => {
this._push(routes.reverseSwap);
};

navReverseExpired = () => {
this._push(routes.reverseExpired);
};
}

export default Navigation;
1 change: 1 addition & 0 deletions src/actions/reverseActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ const handleReverseSwapStatus = (
case SwapUpdateEvent.TransactionRefunded:
source.close();
dispatch(timelockExpired());

break;

case SwapUpdateEvent.InvoiceSettled:
Expand Down
1 change: 1 addition & 0 deletions src/constants/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export const faq = '/faq';
export const refund = '/refund';
export const swap = '/swap';
export const reverseSwap = '/reverseswap';
export const reverseExpired = '/expired';
6 changes: 6 additions & 0 deletions src/views/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const Faq = lazy(() => import('./faq'));
const Swap = lazy(() => import('./swap'));
const Refund = lazy(() => import('./refund'));
const ReverseSwap = lazy(() => import('./reverse'));
const ReverseSwapTimelockExpired = lazy(() => import('./reversetimelock'));

jss.setup(preset);
const App = () => {
Expand All @@ -28,6 +29,11 @@ const App = () => {
<Route exact path={routes.swap} component={Swap} />
<Route exact path={routes.refund} component={Refund} />
<Route exact path={routes.reverseSwap} component={ReverseSwap} />
<Route
exact
path={routes.reverseExpired}
component={ReverseSwapTimelockExpired}
/>
<Route path={'*'} component={LandingPage} />
</Switch>
</Router>
Expand Down
2 changes: 1 addition & 1 deletion src/views/landingpage/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { lazy } from 'react';
import { connect } from 'react-redux';
import PlatformSelector from '../../hoc/platformSelector';
import { initSwap } from '../../actions/swapActions';
import PlatformSelector from '../../hoc/platformSelector';
import * as actions from '../../actions/landingPageActions';
import { initReverseSwap } from '../../actions/reverseActions';

Expand Down
3 changes: 3 additions & 0 deletions src/views/reverse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {
dataStorageSetAsset,
dataStorageSetId,
} from '../../actions/datastorageActions';
import { navigation } from '../../actions';

const mapStateToProps = state => ({
webln: state.reverseSwapReducer.webln,

inSwapMode: state.reverseSwapReducer.inSwapMode,
isFetching: state.reverseSwapReducer.isFetching,
isReconnecting: state.reverseSwapReducer.isReconnecting,
Expand All @@ -31,6 +33,7 @@ const mapDispatchToProps = dispatch => ({
dataStorageSetAsset: (asset, amount) =>
dispatch(dataStorageSetAsset(asset, amount)),
dataStorageSetId: id => dispatch(dataStorageSetId(id)),
goTimelockExpired: () => dispatch(navigation.navReverseExpired()),
});

export default connect(
Expand Down
14 changes: 6 additions & 8 deletions src/views/reverse/reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,20 @@ class ReverseSwap extends React.Component {
swapResponse,
swapInfo,
dataStorageSetId,
dataStorageSetAsset,
} = this.props;

this.redirectIfLoggedOut();

if (
prevProps.swapInfo.quote !== swapInfo.quote &&
prevProps.swapInfo.quoteAmount !== swapInfo.quoteAmount
) {
this.props.dataStorageSetAsset({
if (swapInfo.quote && swapInfo.quoteAmount) {
dataStorageSetAsset({
asset: swapInfo.quote,
amount: swapInfo.quoteAmount,
});
}

if (swapResponse.id !== prevProps.swapResponse.id && swapResponse.id) {
dataStorageSetId(swapResponse);
if (swapResponse.id) {
dataStorageSetId(swapResponse.id);
}

if (isReconnecting && !prevProps.isReconnecting) {
Expand Down Expand Up @@ -250,7 +248,7 @@ ReverseSwap.propTypes = {
isFetching: PropTypes.bool.isRequired,
isReconnecting: PropTypes.bool.isRequired,
inSwapMode: PropTypes.bool.isRequired,
goTimelockExpired: PropTypes.func,
goTimelockExpired: PropTypes.func.isRequired,
webln: PropTypes.object,
swapInfo: PropTypes.object,
swapResponse: PropTypes.object,
Expand Down
83 changes: 45 additions & 38 deletions src/views/reversetimelock/ReverseSwapTimelockExpired.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import injectSheet from 'react-jss';
import { navigation } from '../../action';
import { navigation } from '../../actions';
import View from '../../components/view';
import NavigationBar from '../../components/navigationbar';
import Controls from '../../components/controls';
Expand Down Expand Up @@ -49,51 +49,58 @@ const styles = theme => ({
},
});

const ReverseSwapTimelockExpired = ({
classes,
amount,
asset,
id,
dataStorageClear,
}) => (
<BackGround>
<NavigationBar />
<View className={classes.wrapper}>
<View className={classes.tab}>
<View className={classes.padding}>
<View className={classes.content}>
<h1>
Aw swap! We could not lock your {amount} {asset} for you.
</h1>
<p className={classes.reason}>
The time lock of the locked up funds expired before the invoice
got paid. Therefore, we refunded the coins back to our platform
and aborted the Swap. Please report your Swap ID <i>{id}</i>{' '}
<a href={'https://discordapp.com/invite/cq4dkwQ'}>here</a> to{' '}
learn further details.
</p>
class ReverseSwapTimelockExpired extends React.Component {
componentDidMount = () => {
if (this.props.id === '') {
navigation.navHome();
}
};

render = () => {
const { id, asset, amount, classes, dataStorageClear } = this.props;

return (
<BackGround>
<NavigationBar />
<View className={classes.wrapper}>
<View className={classes.tab}>
<View className={classes.padding}>
<View className={classes.content}>
<h1>
Aw swap! We could not lock your {amount} {asset} for you.
</h1>
<p className={classes.reason}>
The time lock of the locked up funds expired before the
invoice got paid. Therefore, we refunded the coins back to our
platform and aborted the Swap. Please report your Swap ID{' '}
<i>{id}</i>{' '}
<a href={'https://discordapp.com/invite/cq4dkwQ'}>here</a> to{' '}
learn further details.
</p>
</View>
</View>
<View className={classes.retry}>
<Controls
text={'Try another Swap'}
onPress={() => {
window.location.reload();
dataStorageClear();
}}
/>
</View>
</View>
</View>
<View className={classes.retry}>
<Controls
text={'Try another Swap'}
onPress={() => {
dataStorageClear();
navigation.navHome();
}}
/>
</View>
</View>
</View>
</BackGround>
);
</BackGround>
);
};
}

ReverseSwapTimelockExpired.propTypes = {
classes: PropTypes.object.isRequired,
id: PropTypes.string,
asset: PropTypes.string,
amount: PropTypes.number,
dataStorageClear: PropTypes.func,
dataStorageClear: PropTypes.func.isRequired,
};

export default injectSheet(styles)(ReverseSwapTimelockExpired);

0 comments on commit 5ec379d

Please sign in to comment.