Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useBCH.js
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | ) => { | ||||
} | } | ||||
}; | }; | ||||
const sendToken = async ( | const sendToken = async ( | ||||
chronik, | chronik, | ||||
wallet, | wallet, | ||||
{ tokenId, amount, tokenReceiverAddress }, | { tokenId, amount, tokenReceiverAddress }, | ||||
) => { | ) => { | ||||
const xecUtxos = wallet.state.nonSlpUtxos; | const { slpUtxos, nonSlpUtxos } = wallet.state; | ||||
const tokenUtxos = wallet.state.slpUtxos; | |||||
const CREATION_ADDR = wallet.Path1899.cashAddress; | const CREATION_ADDR = wallet.Path1899.cashAddress; | ||||
// Handle error of user having no XEC | // Handle error of user having no XEC | ||||
if (!xecUtxos || xecUtxos.length === 0) { | if (!nonSlpUtxos || nonSlpUtxos.length === 0) { | ||||
throw new Error( | throw new Error( | ||||
`You need some ${currency.ticker} to send ${currency.tokenTicker}`, | `You need some ${currency.ticker} to send ${currency.tokenTicker}`, | ||||
); | ); | ||||
} | } | ||||
// instance of transaction builder | // instance of transaction builder | ||||
let txBuilder = new TransactionBuilder(); | let txBuilder = new TransactionBuilder(); | ||||
let tokenTxInputObj = generateTokenTxInput( | let tokenTxInputObj = generateTokenTxInput( | ||||
'SEND', | 'SEND', | ||||
xecUtxos, | nonSlpUtxos, | ||||
tokenUtxos, | slpUtxos, | ||||
tokenId, | tokenId, | ||||
amount, | amount, | ||||
currency.defaultFee, | currency.defaultFee, | ||||
txBuilder, | txBuilder, | ||||
); | ); | ||||
// update txBuilder object with inputs | // update txBuilder object with inputs | ||||
txBuilder = tokenTxInputObj.txBuilder; | txBuilder = tokenTxInputObj.txBuilder; | ||||
Show All 37 Lines | ) => { | ||||
throw err; | throw err; | ||||
} | } | ||||
// return the explorer link for the broadcasted tx | // return the explorer link for the broadcasted tx | ||||
return `${currency.blockExplorerUrl}/tx/${broadcastResponse.txid}`; | return `${currency.blockExplorerUrl}/tx/${broadcastResponse.txid}`; | ||||
}; | }; | ||||
const burnToken = async (chronik, wallet, { tokenId, amount }) => { | const burnToken = async (chronik, wallet, { tokenId, amount }) => { | ||||
const xecUtxos = wallet.state.nonSlpUtxos; | const { slpUtxos, nonSlpUtxos } = wallet.state; | ||||
const tokenUtxos = wallet.state.slpUtxos; | |||||
const CREATION_ADDR = wallet.Path1899.cashAddress; | const CREATION_ADDR = wallet.Path1899.cashAddress; | ||||
// Handle error of user having no XEC | // Handle error of user having no XEC | ||||
if (!xecUtxos || xecUtxos.length === 0) { | if (!nonSlpUtxos || nonSlpUtxos.length === 0) { | ||||
throw new Error(`You need some ${currency.ticker} to burn eTokens`); | throw new Error(`You need some ${currency.ticker} to burn eTokens`); | ||||
} | } | ||||
// instance of transaction builder | // instance of transaction builder | ||||
let txBuilder = new TransactionBuilder(); | let txBuilder = new TransactionBuilder(); | ||||
let tokenTxInputObj = generateTokenTxInput( | let tokenTxInputObj = generateTokenTxInput( | ||||
'BURN', | 'BURN', | ||||
xecUtxos, | nonSlpUtxos, | ||||
tokenUtxos, | slpUtxos, | ||||
tokenId, | tokenId, | ||||
amount, | amount, | ||||
currency.defaultFee, | currency.defaultFee, | ||||
txBuilder, | txBuilder, | ||||
); | ); | ||||
// update txBuilder object with inputs | // update txBuilder object with inputs | ||||
txBuilder = tokenTxInputObj.txBuilder; | txBuilder = tokenTxInputObj.txBuilder; | ||||
▲ Show 20 Lines • Show All 301 Lines • Show Last 20 Lines |