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

Commit

Permalink
fix(ui): remove channel from closing list on error
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed May 10, 2020
1 parent 626ba70 commit 9cc1999
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 130 deletions.
1 change: 0 additions & 1 deletion renderer/reducers/channels/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const CHANGE_CHANNEL_SORT_ORDER = 'CHANGE_CHANNEL_SORT_ORDER'
export const UPDATE_SEARCH_QUERY = 'UPDATE_SEARCH_QUERY'
export const GET_CHANNELS = 'GET_CHANNELS'
export const RECEIVE_CHANNELS = 'RECEIVE_CHANNELS'
export const CLOSING_CHANNEL = 'CLOSING_CHANNEL'
export const ADD_LOADING_PUBKEY = 'ADD_LOADING_PUBKEY'
export const REMOVE_LOADING_PUBKEY = 'REMOVE_LOADING_PUBKEY'
export const ADD_CLOSING_CHAN_ID = 'ADD_CLOSING_CHAN_ID'
Expand Down
39 changes: 15 additions & 24 deletions renderer/reducers/channels/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const {
UPDATE_SEARCH_QUERY,
GET_CHANNELS,
RECEIVE_CHANNELS,
CLOSING_CHANNEL,
ADD_LOADING_PUBKEY,
REMOVE_LOADING_PUBKEY,
ADD_CLOSING_CHAN_ID,
Expand All @@ -50,7 +49,6 @@ const initialState = {
},
closedChannels: [],
closingChannelIds: [],
closingChannel: false,
searchQuery: null,
filter: new Set([...DEFAULT_FILTER]),
filters: [
Expand Down Expand Up @@ -172,17 +170,6 @@ export function getChannels() {
}
}

/**
* closingChannel - Initialte channel close action.
*
* @returns {object} Action
*/
export function closingChannel() {
return {
type: CLOSING_CHANNEL,
}
}

/**
* updateChannelSearchQuery - Set the current channel serach string.
*
Expand Down Expand Up @@ -345,13 +332,17 @@ export const fetchChannels = () => async dispatch => {
* @param {object} data Channel update notification
* @returns {Function} Thunk
*/
export const pushchannelupdated = ({ nodePubkey, data }) => dispatch => {
export const pushchannelupdated = ({ nodePubkey, chanId, data }) => dispatch => {
dispatch(fetchChannels())
if (data.update === 'chanPending') {
dispatch(removeLoadingChannel(nodePubkey))
if (nodePubkey) {
dispatch(removeLoadingChannel(nodePubkey))
} else if (chanId) {
dispatch(removeClosingChanId(chanId))
}
dispatch(
updateNotification(
{ payload: { pubkey: nodePubkey } },
{ payload: { pubkey: nodePubkey, chanId } },
{
variant: 'success',
message: 'Channel successfully created',
Expand All @@ -368,11 +359,15 @@ export const pushchannelupdated = ({ nodePubkey, data }) => dispatch => {
* @param {object} data Channel error notification
* @returns {Function} Thunk
*/
export const pushchannelerror = ({ nodePubkey, error }) => dispatch => {
dispatch(removeLoadingChannel(nodePubkey))
export const pushchannelerror = ({ nodePubkey, chanId, error }) => dispatch => {
if (nodePubkey) {
dispatch(removeLoadingChannel(nodePubkey))
} else if (chanId) {
dispatch(removeClosingChanId(chanId))
}
dispatch(
updateNotification(
{ payload: { pubkey: nodePubkey } },
{ payload: { pubkey: nodePubkey, chanId } },
{
variant: 'error',
message: error,
Expand Down Expand Up @@ -457,7 +452,6 @@ export const closeChannel = () => async (dispatch, getState) => {

if (selectedChannel) {
const { channelPoint, chanId, active } = selectedChannel
dispatch(closingChannel())
dispatch(addClosingChanId(chanId))

const [fundingTxid, outputIndex] = channelPoint.split(':')
Expand All @@ -477,7 +471,7 @@ export const closeChannel = () => async (dispatch, getState) => {
dispatch(
pushchannelerror({
error: `Unable to close channel: ${e.message}`,
nodePubkey: e.payload.nodePubkey,
chanId: e.payload.chanId,
})
)
}
Expand Down Expand Up @@ -566,9 +560,6 @@ const ACTION_HANDLERS = {
state.pendingChannels = pendingChannels
state.closedChannels = closedChannels
},
[CLOSING_CHANNEL]: state => {
state.closingChannel = true
},
[UPDATE_SEARCH_QUERY]: (state, { searchQuery }) => {
state.searchQuery = searchQuery
},
Expand Down
97 changes: 0 additions & 97 deletions test/unit/reducers/__snapshots__/channels.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Snapshot Diff:
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
- "closingChannelIds": Array [],
+ "closingChannelIds": Array [
+ "123",
Expand Down Expand Up @@ -94,7 +93,6 @@ Snapshot Diff:
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -181,7 +179,6 @@ Snapshot Diff:
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -263,7 +260,6 @@ Snapshot Diff:
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -346,7 +342,6 @@ Snapshot Diff:
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -420,89 +415,6 @@ Snapshot Diff:
}
`;

exports[`reducers channelsReducer should handle CLOSING_CHANNEL 1`] = `
Snapshot Diff:
- First value
+ Second value
Object {
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
- "closingChannel": false,
+ "closingChannel": true,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
"NON_ACTIVE_CHANNELS",
"OPEN_PENDING_CHANNELS",
"CLOSING_PENDING_CHANNELS",
},
"filters": Array [
Object {
"key": "ACTIVE_CHANNELS",
"value": "Online",
},
Object {
"key": "NON_ACTIVE_CHANNELS",
"value": "Offline",
},
Object {
"key": "OPEN_PENDING_CHANNELS",
"value": "Pending",
},
Object {
"key": "CLOSING_PENDING_CHANNELS",
"value": "Closing",
},
],
"loadingChannels": Array [],
"pendingChannels": Object {
"pendingClosingChannels": Array [],
"pendingForceClosingChannels": Array [],
"pendingOpenChannels": Array [],
"totalLimboBalance": "0",
"waitingCloseChannels": Array [],
},
"searchQuery": null,
"selectedChannelId": null,
"sort": "CHANNELS_SORT_OPEN_DATE",
"sortOrder": "asc",
"sorters": Array [
Object {
"key": "CHANNELS_SORT_OPEN_DATE",
"value": "Open date",
},
Object {
"key": "CHANNELS_SORT_REMOTE_BALANCE",
"value": "Remote balance",
},
Object {
"key": "CHANNELS_SORT_LOCAL_BALANCE",
"value": "Local balance",
},
Object {
"key": "CHANNELS_SORT_ACTIVITY",
"value": "Activity",
},
Object {
"key": "CHANNELS_SORT_NAME",
"value": "Name",
},
Object {
"key": "CHANNELS_SORT_CAPACITY",
"value": "Capacity",
},
],
"suggestedNodes": Object {
"mainnet": Array [],
"testnet": Array [],
},
"suggestedNodesError": null,
"suggestedNodesLoading": false,
}
`;

exports[`reducers channelsReducer should handle GET_CHANNELS 1`] = `
Snapshot Diff:
- First value
Expand All @@ -513,7 +425,6 @@ Snapshot Diff:
- "channelsLoading": false,
+ "channelsLoading": true,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -595,7 +506,6 @@ Snapshot Diff:
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -686,7 +596,6 @@ Snapshot Diff:
+ 5,
+ 6,
+ ],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -781,7 +690,6 @@ Snapshot Diff:
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -864,7 +772,6 @@ Snapshot Diff:
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -957,7 +864,6 @@ Snapshot Diff:
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -1040,7 +946,6 @@ Snapshot Diff:
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -1123,7 +1028,6 @@ Snapshot Diff:
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down Expand Up @@ -1202,7 +1106,6 @@ Object {
"channels": Array [],
"channelsLoading": false,
"closedChannels": Array [],
"closingChannel": false,
"closingChannelIds": Array [],
"filter": Set {
"ACTIVE_CHANNELS",
Expand Down
8 changes: 0 additions & 8 deletions test/unit/reducers/channels.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import reducer, {
UPDATE_SEARCH_QUERY,
GET_CHANNELS,
RECEIVE_CHANNELS,
CLOSING_CHANNEL,
ADD_LOADING_PUBKEY,
REMOVE_LOADING_PUBKEY,
ADD_CLOSING_CHAN_ID,
Expand Down Expand Up @@ -95,13 +94,6 @@ describe('reducers', () => {
expect(snapshotDiff(reducer(undefined, {}), reducer(undefined, action))).toMatchSnapshot()
})

it('should handle CLOSING_CHANNEL', () => {
const action = {
type: CLOSING_CHANNEL,
}
expect(snapshotDiff(reducer(undefined, {}), reducer(undefined, action))).toMatchSnapshot()
})

it('should handle ADD_LOADING_PUBKEY', () => {
const action = {
type: ADD_LOADING_PUBKEY,
Expand Down

0 comments on commit 9cc1999

Please sign in to comment.