Skip to content

Commit 8855eba

Browse files
authored
Merge pull request #182 from liquality/dev
Fix order of claim wallet popups - Fixes both ledger claim bug
2 parents 070fc90 + 608030a commit 8855eba

File tree

4 files changed

+47
-19
lines changed

4 files changed

+47
-19
lines changed

src/actions/swap.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ async function setInitiationWalletPopups (confirm, dispatch, getState) {
104104
wallets
105105
} = getState().swap
106106
const popup = getActionPopups(SWAP_STAGES.INITIATE, assets.a.currency, wallets.a.type)
107-
if (!popup) return
108107
const popupSteps = popup.steps
109108
const theSteps = confirm ? [popupSteps[1]] : popupSteps
110109
dispatch(walletActions.setPopupSteps(theSteps))
@@ -119,12 +118,10 @@ async function setClaimWalletPopups (sign, dispatch, getState) {
119118
const claimTransactionPopup = getActionPopups(SWAP_STAGES.CLAIM, assets.b.currency, wallets.b.type)
120119
const steps = []
121120

122-
if (sign && signTransactionPopup) {
121+
if (sign) {
123122
steps.push(signTransactionPopup.steps[0])
124123
}
125-
if (claimTransactionPopup) {
126-
steps.push(claimTransactionPopup.steps[1])
127-
}
124+
steps.push(claimTransactionPopup.steps[1])
128125

129126
dispatch(walletActions.setPopupSteps(steps))
130127
}
@@ -135,9 +132,7 @@ async function setRefundWalletSteps (dispatch, getState) {
135132
wallets
136133
} = getState().swap
137134
const refundTransactionPopups = getActionPopups(SWAP_STAGES.REFUND, assets.a.currency, wallets.a.type)
138-
if (refundTransactionPopups) {
139-
dispatch(walletActions.setPopupSteps([refundTransactionPopups.steps[1]]))
140-
}
135+
dispatch(walletActions.setPopupSteps([refundTransactionPopups.steps[1]]))
141136
}
142137

143138
async function generateSecret (dispatch, getState) {
@@ -328,13 +323,13 @@ function redeemSwap () {
328323
const secretRequired = !isPartyB && !secretParams.secret
329324
if (secretRequired) {
330325
await ensureWallet('a', dispatch, getState)
331-
}
332-
await ensureWallet('b', dispatch, getState)
333-
await setClaimWalletPopups(secretRequired, dispatch, getState)
334-
if (secretRequired) {
326+
await setClaimWalletPopups(secretRequired, dispatch, getState)
335327
await withWalletPopupStep(WALLET_ACTION_STEPS.SIGN, dispatch, getState, generateSecret)
336328
}
329+
await setClaimWalletPopups(secretRequired, dispatch, getState)
337330
await withWalletPopupStep(WALLET_ACTION_STEPS.CONFIRM, dispatch, getState, async () => {
331+
await ensureWallet('b', dispatch, getState)
332+
await setClaimWalletPopups(secretRequired, dispatch, getState)
338333
await withLoadingMessage('b', dispatch, getState, unlockFunds)
339334
})
340335
}

src/actions/wallets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function disconnectWallet (party) {
7272
return async (dispatch, getState) => {
7373
const swap = getState().swap
7474
dispatch({ type: types.DISCONNECT_WALLET, party, preserveAddress: swap.isPartyB || swap.step !== steps.INITIATION })
75+
dispatch(closePopup())
7576
}
7677
}
7778

src/components/WalletActionPopup/WalletActionPopup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class WalletActionPopup extends Component {
3939
<div className='WalletActionPopup_instructions'>
4040
<div className='WalletActionPopup_message'>
4141
<p>{activeStep.description}</p>
42-
<img src={activeStep.image} alt={activeStep.description} />
42+
{activeStep.image && <img src={activeStep.image} alt={activeStep.description} />}
4343
</div>
4444
</div>
4545
</div>

src/utils/walletActionPopups.js

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const ethereumLedgerPopup = {
2626
]
2727
}
2828

29-
const ledgerERC20Popup = {
29+
const ERC20LedgerPopup = {
3030
steps: [
3131
{ id: WALLET_ACTION_STEPS.SIGN, title: 'On your Ledger', type: 'Ethereum', label: 'Sign Message', description: 'View displayed hash, then sign', image: require('../icons/wallets/ledger/device.svg') },
3232
{ id: WALLET_ACTION_STEPS.CONFIRM, title: 'On your Ledger', type: 'Ethereum', label: 'Confirm Transactions', description: 'Sign 2 transactions to confirm. Expect a lag in between them.', image: require('../icons/wallets/ledger/device.svg') }
@@ -47,6 +47,20 @@ const ERC20MetamaskPopup = {
4747
]
4848
}
4949

50+
const defaultPopup = {
51+
steps: [
52+
{ id: WALLET_ACTION_STEPS.SIGN, title: 'On Your Wallet', label: 'Sign Message', description: 'View displayed hash, then sign' },
53+
{ id: WALLET_ACTION_STEPS.CONFIRM, title: 'On Your Wallet', label: 'Confirm Transaction', description: 'Confirm the transaction.' }
54+
]
55+
}
56+
57+
const defaultERC20Popup = {
58+
steps: [
59+
{ id: WALLET_ACTION_STEPS.SIGN, title: 'On Your Wallet', label: 'Sign Message', description: 'View displayed hash, then sign' },
60+
{ id: WALLET_ACTION_STEPS.CONFIRM, title: 'On Your Wallet', label: 'Confirm Transactions', description: 'Sign 2 transactions to confirm. After the first confirmation there is a lag before the MetaMask popup displays again.' }
61+
]
62+
}
63+
5064
function toClaimPopup (popup) {
5165
return { steps: popup.steps.map(step => {
5266
return step.id === WALLET_ACTION_STEPS.CONFIRM ? {...step, description: 'Confirm to claim your assets.'} : step
@@ -63,11 +77,16 @@ const initiatePopups = {
6377
ledger: {
6478
btc: bitcoinLedgerPopup,
6579
eth: ethereumLedgerPopup,
66-
erc20: ledgerERC20Popup
80+
erc20: ERC20LedgerPopup
6781
},
6882
metamask: {
6983
eth: ethereumMetamaskPopup,
7084
erc20: ERC20MetamaskPopup
85+
},
86+
default: {
87+
btc: defaultPopup,
88+
eth: defaultPopup,
89+
erc20: defaultERC20Popup
7190
}
7291
}
7392

@@ -80,6 +99,11 @@ const claimPopups = {
8099
metamask: {
81100
eth: toClaimPopup(ethereumMetamaskPopup),
82101
erc20: toClaimPopup(ERC20MetamaskPopup)
102+
},
103+
default: {
104+
btc: toClaimPopup(defaultPopup),
105+
eth: toClaimPopup(defaultPopup),
106+
erc20: toClaimPopup(defaultERC20Popup)
83107
}
84108
}
85109

@@ -92,6 +116,11 @@ const refundPopups = {
92116
metamask: {
93117
eth: toRefundPopup(ethereumMetamaskPopup),
94118
erc20: toRefundPopup(ERC20MetamaskPopup)
119+
},
120+
default: {
121+
btc: toRefundPopup(defaultPopup),
122+
eth: toRefundPopup(defaultPopup),
123+
erc20: toRefundPopup(defaultERC20Popup)
95124
}
96125
}
97126

@@ -104,11 +133,14 @@ const popups = {
104133
// TODO: make more generic to cover all wallet types
105134
function getActionPopups (stage, asset, wallet) {
106135
const assetConfig = config.assets[asset]
107-
if (wallet.includes('ledger')) {
108-
return popups[stage].ledger[assetConfig.type || asset]
109-
} else if (wallet.includes('metamask')) {
110-
return popups[stage].metamask[assetConfig.type || asset]
136+
if (wallet) {
137+
if (wallet.includes('ledger')) {
138+
return popups[stage].ledger[assetConfig.type || asset]
139+
} else if (wallet.includes('metamask')) {
140+
return popups[stage].metamask[assetConfig.type || asset]
141+
}
111142
}
143+
return popups[stage].default[assetConfig.type || asset]
112144
}
113145

114146
export { getActionPopups, WALLET_ACTION_STEPS, SWAP_STAGES }

0 commit comments

Comments
 (0)