Skip to content

Commit 5623ae9

Browse files
authored
Merge pull request #6037 from blockchain/release/v4.92
Release/v4.92
2 parents 33e2876 + 89f8347 commit 5623ae9

File tree

16 files changed

+79
-136
lines changed

16 files changed

+79
-136
lines changed

legacy-pages/import-wallet.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
<script src="js/import/wallet-import.js" nonce="**CSP_NONCE**" type="text/javascript"></script>
2222
<script nonce="**CSP_NONCE**">
2323
window.NONCE = '**CSP_NONCE**'
24-
window.CAPTCHA_KEY = '**RECAPTCHA_KEY**'
24+
window.CAPTCHA_KEY = '6LcxysYaAAAAAOf5QgMWz-GXzoXjpvSrSXETmtlU'
2525
window.SARDINE_CLIENT_ID = '**SARDINE_CLIENT_ID**'
2626
window.SARDINE_ENVIRONMENT = '**SARDINE_ENVIRONMENT**'
2727
</script>
28-
<script
29-
nonce="**CSP_NONCE**"
30-
rel="prefetch"
31-
src="https://www.google.com/recaptcha/enterprise.js?render=**RECAPTCHA_KEY**"
32-
></script>
28+
<script
29+
nonce="**CSP_NONCE**"
30+
rel="prefetch"
31+
src="https://www.google.com/recaptcha/enterprise.js?render=6LcxysYaAAAAAOf5QgMWz-GXzoXjpvSrSXETmtlU"
32+
></script>
3333
</head>
3434
<body data-war-checksum="1e64a0eb9697314b" class="opaque-nav" id="home-container">
3535
<nav role="navigation">

legacy-pages/js/import/wallet-import.js

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
;(function () {
22
//Save the javascript wallet to the remote server
3-
function reallyInsertWallet(guid, sharedKey, password, successcallback) {
3+
async function reallyInsertWallet(guid, sharedKey, password, successcallback) {
44
// Executing google recaptcha
5-
var captcha = generateCaptchaToken()
5+
await initCaptcha()
66
var _errorcallback = function (e) {
77
MyWallet.makeNotice('error', 'misc-error', 'Error Saving Wallet: ' + e, 10000)
88
throw e
@@ -34,12 +34,14 @@
3434
{
3535
length: crypted.length,
3636
payload: crypted,
37-
captcha: captcha,
37+
captcha: window.NEW_CAPTCHA_TOKEN,
3838
checksum: new_checksum,
3939
method: 'insert',
4040
format: 'plain',
4141
sharedKey: sharedKey,
42-
guid: guid
42+
guid: guid,
43+
siteKey: window.CAPTCHA_KEY,
44+
ct: Date.now()
4345
},
4446
function (data) {
4547
MyWallet.makeNotice('success', 'misc-success', data)
@@ -150,7 +152,6 @@
150152
type: 'GET',
151153
url: 'https://blockchain.info/uuid-generator',
152154
data: {
153-
api_code: '1770d5d9-bcea-4d28-ad21-6cbd5be018a8',
154155
ct: new Date().getTime(),
155156
format: 'json',
156157
n: n
@@ -284,46 +285,23 @@
284285
evt.dataTransfer.dropEffect = 'copy' // Explicitly show this is a copy.
285286
}
286287

287-
// function initCaptcha() {
288-
// if (!window.grecaptcha || !window.grecaptcha.enterprise) return
289-
// window.grecaptcha.enterprise.ready(() => {
290-
// window.grecaptcha.enterprise
291-
// .execute(window.CAPTCHA_KEY, { action: 'LEGACY_WALLET_IMPORT' })
292-
// .then((captchaToken) => {
293-
// console.log('Captcha success', captchaToken)
294-
// window.NEWRECAPCHA = captchaToken
295-
// })
296-
// .catch((e) => {
297-
// console.error('Captcha error: ', e)
298-
// })
299-
// })
300-
// }
301-
302-
function generateCaptchaToken() {
303-
let pollCount = 0
304-
305-
// wait up to 10 seconds for captcha library to load
306-
while (true) {
307-
pollCount += 1
308-
309-
if (pollCount >= 50) {
310-
console.error('Captcha: window.grecaptcha not found')
311-
break
312-
}
313-
if (window.grecaptcha && window.grecaptcha.enterprise) {
314-
break
315-
}
316-
}
317-
const getToken = () =>
318-
window.grecaptcha.enterprise
319-
.execute(window.CAPTCHA_KEY, { action: 'LEGACY_WALLET_IMPORT' })
320-
.then((token) => token)
321-
.catch((e) => {
322-
console.error('Captcha: ', e)
323-
})
324-
325-
const captchaToken = getToken()
326-
return captchaToken
288+
function initCaptcha() {
289+
if (!window.grecaptcha || !window.grecaptcha.enterprise) return
290+
return new Promise((resolve, reject) => {
291+
window.grecaptcha.enterprise.ready(() => {
292+
window.grecaptcha.enterprise
293+
.execute(window.CAPTCHA_KEY, { action: 'LEGACY_WALLET_IMPORT' })
294+
.then((captchaToken) => {
295+
console.log('Captcha success', captchaToken)
296+
window.NEW_CAPTCHA_TOKEN = captchaToken
297+
resolve()
298+
})
299+
.catch((e) => {
300+
console.error('Captcha error: ', e)
301+
reject(e)
302+
})
303+
})
304+
})
327305
}
328306

329307
$(document).ready(function () {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blockchain-wallet-v4",
3-
"version": "4.91.0",
3+
"version": "4.92.3",
44
"license": "AGPL-3.0-or-later",
55
"private": true,
66
"author": {

packages/blockchain-wallet-v4-frontend/src/assets/locales/en.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,8 +2002,6 @@
20022002
"networkWarning.send.title": "Only send {symbol} on the {network} network",
20032003
"orderdetails.recurring.tooltip": "Recurring orders will be placed automatically on a regular basis from your linked credit card.",
20042004
"paymentMethods.bankWire.message": "If you'd prefer to deposit funds directly from your bank account first, follow the instructions on the next screen. Once your deposit arrives in your Blockchain.com account you can come back here to buy crypto.",
2005-
"price.chart.buy.coin": "Buy {coinName}",
2006-
"price.chart.swap.coin": "Swap {coinName}",
20072005
"scene.coinView.activitySection.accountDropdownLable": "All Accounts",
20082006
"scene.debit_card.accounts_fail": "Failed to load accounts",
20092007
"scene.debit_card.funds_fail": "Failed to load balances",

packages/blockchain-wallet-v4-frontend/src/data/components/dex/sagas.ts

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Task from 'data.task'
22
import { addMilliseconds } from 'date-fns'
33
import * as ethers from 'ethers'
44
import { initialize } from 'redux-form'
5-
import { call, delay, put, select } from 'typed-redux-saga'
5+
import { call, delay, put, select, take } from 'typed-redux-saga'
66

77
import { Exchange } from '@core'
88
import { APIType } from '@core/network/api'
@@ -112,6 +112,9 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
112112
step: DexSwapSteps.ENTER_DETAILS
113113
})
114114
)
115+
if (tokensWithBalance[0].symbol !== NATIVE_TOKEN)
116+
yield put(A.fetchTokenAllowance({ baseToken: tokensWithBalance[0].symbol }))
117+
115118
yield put(A.setTokens(tokens))
116119
yield put(A.fetchChains())
117120
} else {
@@ -167,6 +170,11 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
167170
yield* select()
168171
) as DexSwapForm
169172

173+
const isTokenAllowed = S.getTokenAllowanceStatus(yield select()).getOrElse(false)
174+
const isTokenAllowedAfterPolling = S.getTokenAllowanceStatusAfterPolling(
175+
yield select()
176+
).getOrElse(false)
177+
170178
if (
171179
!formValues ||
172180
formValues.isFlipping ||
@@ -175,8 +183,9 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
175183
return yield put(A.stopPollSwapQuote())
176184
}
177185

178-
const { baseToken, baseTokenAmount, counterToken, counterTokenAmount, slippage, step } =
186+
const { baseToken, baseTokenAmount, counterToken, counterTokenAmount, slippage } =
179187
formValues
188+
180189
if (
181190
baseToken &&
182191
counterToken &&
@@ -211,12 +220,6 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
211220
throw Error('No counter token')
212221
}
213222

214-
const counterAmount = Exchange.convertCoinToCoin({
215-
baseToStandard: false,
216-
coin: counterToken,
217-
value: counterTokenAmount || 0
218-
})
219-
220223
const nonCustodialCoinAccounts = selectors.coins.getCoinAccounts(yield* select(), {
221224
coins: [baseToken, NATIVE_TOKEN],
222225
nonCustodialAccounts: true
@@ -229,34 +232,24 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
229232
throw Error('No user wallet address')
230233
}
231234

232-
const sideType = yield select(S.getSwapSideType)
233-
234235
const quoteResponse = yield* call(api.getDexSwapQuote, {
235236
fromCurrency: {
236237
address: baseTokenInfo.address,
237-
amount: sideType === DexSwapSide.BASE ? baseAmount : undefined,
238+
amount: baseAmount,
238239
chainId: currentChain.chainId,
239240
symbol: baseToken
240241
},
241242
params: {
242-
skipValidation: step === DexSwapSteps.ENTER_DETAILS,
243+
skipValidation:
244+
!isTokenAllowed && !isTokenAllowedAfterPolling && baseToken !== NATIVE_TOKEN,
243245
slippage: `${slippage}`
244246
},
245-
246-
// User always has a private wallet setup automatically on sign up but should go through a security phrase
247-
// in order to receive funds. If he didn't do it he has 0 balance and just nothing to swap. We don't need
248-
// any additional checks here to make sure user can use a wallet
249-
// TODO: Pass selected wallet not the first one when we have more than 1 wallet
250247
takerAddress: `${nonCustodialAddress}`,
251-
252248
toCurrency: {
253249
address: counterTokenInfo.address,
254-
amount: sideType === DexSwapSide.COUNTER ? counterAmount : undefined,
255250
chainId: currentChain.chainId,
256251
symbol: counterToken
257252
},
258-
259-
// Hardcoded now. In future get it from: https://{{dex_url}}/v1/venues
260253
venue: 'ZEROX' as const
261254
})
262255

@@ -272,13 +265,13 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
272265
const { quote, quoteTtl, transaction } = quoteResponse
273266

274267
if (quote) {
275-
const nonEthCustodialbalance = nonCustodialCoinAccounts[NATIVE_TOKEN][0].balance
268+
const nonEthCustodialBalance = nonCustodialCoinAccounts[NATIVE_TOKEN][0].balance
276269
const { gasLimit, gasPrice } = transaction
277-
const gasLimitBn = ethers.BigNumber.from(gasLimit)
278-
const gasPriceBn = ethers.BigNumber.from(gasPrice)
270+
const gasLimitBn = ethers.BigNumber.from(gasLimit || '0')
271+
const gasPriceBn = ethers.BigNumber.from(gasPrice || '0')
279272
const gasFee = gasLimitBn.mul(gasPriceBn)
280273

281-
if (gasFee.gt(nonEthCustodialbalance)) {
274+
if (gasFee.gt(nonEthCustodialBalance)) {
282275
// eslint-disable-next-line no-throw-literal
283276
throw {
284277
message: 'Not enough ETH to cover gas.',
@@ -355,9 +348,14 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
355348
}
356349

357350
// reset insufficient balance error if user changes token
358-
if (field === 'baseToken') {
351+
if (baseToken && field === 'baseToken') {
359352
const error = yield select(selectors.components.dex.getSwapQuote)
360353
if (error) yield put(A.clearCurrentSwapQuote())
354+
355+
if (baseToken !== NATIVE_TOKEN) {
356+
yield put(A.fetchTokenAllowance({ baseToken }))
357+
yield take([A.fetchTokenAllowanceSuccess, A.fetchTokenAllowanceFailure])
358+
}
361359
}
362360

363361
// if base amount is not enough, trigger insufficient balance error
@@ -389,18 +387,7 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
389387
}
390388
}
391389

392-
if (
393-
!counterToken ||
394-
!baseToken ||
395-
!(getValidSwapAmount(baseTokenAmount) || getValidSwapAmount(counterTokenAmount))
396-
)
397-
return
398-
399-
if (field === 'baseTokenAmount') {
400-
yield put(A.setSwapSideType(DexSwapSide.BASE))
401-
} else {
402-
yield put(A.setSwapSideType(DexSwapSide.COUNTER))
403-
}
390+
if (!counterToken || !baseToken || !getValidSwapAmount(baseTokenAmount)) return
404391

405392
yield put(A.fetchSwapQuote())
406393
}

packages/blockchain-wallet-v4-frontend/src/data/components/dex/selectors.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,3 @@ export const getTokenAllowanceStatusAfterPolling = (state: RootState) =>
3232
state.components.dex.isTokenAllowedAfterPolling
3333

3434
export const getSwapQuoteTx = (state: RootState) => state.components.dex.swapQuoteTx
35-
36-
export const getSwapSideType = (state: RootState) => state.components.dex.swapSideType

packages/blockchain-wallet-v4-frontend/src/data/components/dex/slice.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { CoinType } from '@core/types'
77
import {
88
DexStateType,
99
DexSwapQuoteWithDate,
10-
DexSwapSide,
1110
DexToken,
1211
ParsedTx,
1312
QuoteError,
@@ -22,7 +21,6 @@ const initialState: DexStateType = {
2221
isUserEligible: Remote.NotAsked,
2322
swapQuote: Remote.NotAsked,
2423
swapQuoteTx: Remote.NotAsked,
25-
swapSideType: DexSwapSide.BASE,
2624
tokenAllowanceGasEstimate: '',
2725
tokenAllowanceTx: Remote.NotAsked,
2826
tokens: []
@@ -122,9 +120,6 @@ const dexSlice = createSlice({
122120
setCurrentChain: (state, action: PayloadAction<DexChain>) => {
123121
state.currentChain = Remote.Success(action.payload)
124122
},
125-
setSwapSideType: (state, action: PayloadAction<DexSwapSide>) => {
126-
state.swapSideType = action.payload
127-
},
128123
setTokenAllowanceGasEstimate: (state, action: PayloadAction<string>) => {
129124
state.tokenAllowanceGasEstimate = action.payload
130125
},

packages/blockchain-wallet-v4-frontend/src/data/components/dex/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { DexChain, DexSwapQuote } from '@core/network/api/dex'
44
import { CoinType, RemoteDataType } from '@core/types'
55

66
export type ParsedTx = {
7-
chainId: string
7+
chainId: number
88
data: string
99
gasLimit: string
1010
gasPrice: string
@@ -54,7 +54,6 @@ export type DexStateType = {
5454
isUserEligible: RemoteDataType<string, boolean>
5555
swapQuote: RemoteDataType<QuoteError, DexSwapQuoteWithDate>
5656
swapQuoteTx: RemoteDataType<string, SwapQuoteSuccess>
57-
swapSideType: DexSwapSide
5857
tokenAllowanceGasEstimate: string
5958
tokenAllowanceTx: RemoteDataType<string, ParsedTx>
6059
tokens: DexToken[]
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { BigNumber } from 'ethers'
2+
13
import { BuildDexTx } from '@core/network/api/dex/types'
24

35
import { ParsedTx } from '../types'
@@ -9,12 +11,12 @@ export const parseRawTx = (tx: BuildDexTx): ParsedTx => {
911
const { chainId, data, gasLimit, gasPrice, nonce, to, value } = payload
1012

1113
return {
12-
chainId,
14+
chainId: Number(chainId),
1315
data,
14-
gasLimit,
15-
gasPrice,
16+
gasLimit: BigNumber.from(gasLimit).toHexString(),
17+
gasPrice: BigNumber.from(gasPrice).toHexString(),
1618
nonce,
1719
to,
18-
value
20+
value: BigNumber.from(value).toHexString()
1921
}
2022
}

0 commit comments

Comments
 (0)