Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 5887ab7

Browse files
committed
feat(new send): testing stuff
1 parent bcc67b2 commit 5887ab7

2 files changed

Lines changed: 76 additions & 4 deletions

File tree

  • packages
    • blockchain-wallet-v4-frontend/src/data/components/sendCrypto
    • blockchain-wallet-v4/src/utils

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

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import BigNumber from 'bignumber.js'
2+
import * as Bitcoin from 'bitcoinjs-lib'
23
import { SEND_FORM } from 'blockchain-wallet-v4-frontend/src/modals/SendCrypto/model'
34
import { SendFormType } from 'blockchain-wallet-v4-frontend/src/modals/SendCrypto/types'
5+
import { nth } from 'ramda'
46
import { call, delay, put, select } from 'redux-saga/effects'
57
import secp256k1 from 'secp256k1'
68

7-
import { Exchange } from '@core'
9+
import { Exchange, utils } from '@core'
810
import { convertCoinToCoin, convertFiatToCoin } from '@core/exchange'
911
import { APIType } from '@core/network/api'
1012
import { BuildTxIntentType, BuildTxResponseType } from '@core/network/api/coin/types'
@@ -19,6 +21,7 @@ import { Analytics } from 'data/types'
1921
import { AccountType } from 'middleware/analyticsMiddleware/types'
2022
import { promptForSecondPassword } from 'services/sagas'
2123

24+
import coinSagas from '../../coins/sagas'
2225
import sendSagas from '../send/sagas'
2326
import * as S from './selectors'
2427
import { actions as A } from './slice'
@@ -39,6 +42,12 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
3942
networks
4043
})
4144

45+
const { getNextReceiveAddressForCoin } = coinSagas({
46+
api,
47+
coreSagas,
48+
networks
49+
})
50+
4251
const initializeSend = function* () {
4352
const totalBalanceR = yield select(selectors.balances.getTotalWalletBalanceNotFormatted)
4453
const totalBalance = totalBalanceR.getOrElse({ total: 0 })
@@ -70,9 +79,70 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
7079
if (nonMigratedCoins.includes(coin)) {
7180
// TODO simulate buildTx logic for non migrated coins
7281
// only PK accounts will go here
82+
// return
83+
84+
// console.log('all details', { account, baseCryptoAmt, destination, fee, memo })
85+
const accountsR = yield select(selectors.core.common.btc.getAccountsBalances)
86+
// const txS = yield select(selectors.core.common.btc.getWalletTransactions)
87+
// console.log('txS', txS)
88+
if (account.accountIndex !== undefined) {
89+
// const defaultAccount = accountsR.map(nth(account?.accountIndex)).getOrElse({})
90+
// console.log('defaultAccountR', defaultAccount)
91+
// const pubb = Bitcoin.payments.p2pkh({
92+
// pubkey: Bitcoin.bip32.fromBase58(defaultAccount.xpub).derive(0).derive(1).publicKey
93+
// })
94+
// const addressDefault = yield call(getNextReceiveAddressForCoin, coin)
95+
// console.log('addresst', pubb.address)
96+
// console.log('address6', addressDefault)
97+
// const addresst = utils.btc.keyPairToAddress(defaultAccount.xpub)
98+
// console.log('addresst', addresst)
99+
// const defaultAccount = allAccount[account.accountIndex]
100+
// console.log('defaultAccount', defaultAccount)
101+
}
102+
103+
// console.log('defaultAccount', defaultAccount)
104+
105+
const tx = {} as BuildTxResponseType
106+
107+
if (coin === 'BTC') {
108+
// const txBTC = new Bitcoin.TransactionBuilder()
109+
110+
let payment = coreSagas.payment.btc.create({
111+
network: networks.btc
112+
})
113+
payment = yield payment.init()
114+
115+
payment = yield payment.from(account.accountIndex, ADDRESS_TYPES.ACCOUNT)
116+
117+
// console.log('payment', payment)
118+
119+
// from
120+
payment = yield payment.from(account.index, account.type)
121+
// to
122+
payment = yield payment.to(destination, account.type)
123+
// amount
124+
const satAmount = Exchange.convertCoinToCoin({
125+
baseToStandard: false,
126+
coin,
127+
value: baseCryptoAmt
128+
})
129+
payment = yield payment.amount(parseInt(satAmount))
130+
131+
// build transaction
132+
try {
133+
payment = yield payment.build()
134+
135+
// console.log('payment ready', payment.value())
136+
} catch (e) {
137+
yield put(actions.logs.logErrorMessage(logLocation, 'formChanged', e))
138+
}
139+
// console.log('pubKey', pubKey)
140+
// console.log('txBTC', txBTC)
141+
}
142+
143+
yield put(A.buildTxSuccess(tx))
73144
return
74145
}
75-
76146
const tx: ReturnType<typeof api.buildTx> = yield call(api.buildTx, {
77147
id: {
78148
guid,

packages/blockchain-wallet-v4/src/utils/btc.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { compose, dropLast, equals, head, last, or, propOr } from 'ramda'
1111
import { selectAll } from '../coinSelection'
1212
import * as Exchange from '../exchange'
1313

14+
export const keyPairToAddress = (key) => payments.p2pkh({ pubkey: key.publicKey }).address
15+
1416
export const isValidBtcAddress = (value, network) => {
1517
try {
1618
const addr = address.fromBase58Check(value)
@@ -222,6 +224,7 @@ export const getWifAddress = (key, compressed = true) => {
222224
}
223225

224226
export const compressPublicKey = (publicKey) => {
227+
// eslint-disable-next-line
225228
const prefix = (publicKey[64] & 1) !== 0 ? 0x03 : 0x02
226229
const prefixBuffer = Buffer.alloc(1)
227230
prefixBuffer[0] = prefix
@@ -230,6 +233,7 @@ export const compressPublicKey = (publicKey) => {
230233

231234
export const fingerprint = (publickey) => {
232235
const pkh = compose(crypto.ripemd160, crypto.sha256)(publickey)
236+
// eslint-disable-next-line
233237
return ((pkh[0] << 24) | (pkh[1] << 16) | (pkh[2] << 8) | pkh[3]) >>> 0
234238
}
235239

@@ -250,5 +254,3 @@ export const createXpubFromChildAndParent = (path, child, parent) => {
250254

251255
return hdnode.neutered().toBase58()
252256
}
253-
254-
export const keyPairToAddress = (key) => payments.p2pkh({ pubkey: key.publicKey }).address

0 commit comments

Comments
 (0)