Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useBCH.js
Show All 37 Lines | const createToken = async ( | ||||
configObj, | configObj, | ||||
) => { | ) => { | ||||
try { | try { | ||||
// Throw error if wallet does not have utxo set in state | // Throw error if wallet does not have utxo set in state | ||||
if (!isValidStoredWallet(wallet)) { | if (!isValidStoredWallet(wallet)) { | ||||
const walletError = new Error(`Invalid wallet`); | const walletError = new Error(`Invalid wallet`); | ||||
throw walletError; | throw walletError; | ||||
} | } | ||||
const utxos = wallet.state.slpBalancesAndUtxos.nonSlpUtxos; | const utxos = wallet.state.nonSlpUtxos; | ||||
const CREATION_ADDR = wallet.Path1899.cashAddress; | const CREATION_ADDR = wallet.Path1899.cashAddress; | ||||
let txBuilder = new TransactionBuilder(); | let txBuilder = new TransactionBuilder(); | ||||
let tokenTxInputObj = generateTokenTxInput( | let tokenTxInputObj = generateTokenTxInput( | ||||
'GENESIS', | 'GENESIS', | ||||
utxos, | utxos, | ||||
null, // total token UTXOS - not applicable for GENESIS tx | null, // total token UTXOS - not applicable for GENESIS tx | ||||
null, // token ID - not applicable for GENESIS tx | null, // token ID - not applicable for GENESIS tx | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | ) => { | ||||
} | } | ||||
}; | }; | ||||
const sendToken = async ( | const sendToken = async ( | ||||
chronik, | chronik, | ||||
wallet, | wallet, | ||||
{ tokenId, amount, tokenReceiverAddress }, | { tokenId, amount, tokenReceiverAddress }, | ||||
) => { | ) => { | ||||
const slpBalancesAndUtxos = wallet.state.slpBalancesAndUtxos; | const xecUtxos = wallet.state.nonSlpUtxos; | ||||
const xecUtxos = slpBalancesAndUtxos.nonSlpUtxos; | const tokenUtxos = wallet.state.slpUtxos; | ||||
const tokenUtxos = slpBalancesAndUtxos.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 ( | if (!xecUtxos || xecUtxos.length === 0) { | ||||
!slpBalancesAndUtxos || | |||||
!slpBalancesAndUtxos.nonSlpUtxos || | |||||
slpBalancesAndUtxos.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(); | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 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 slpBalancesAndUtxos = wallet.state.slpBalancesAndUtxos; | const xecUtxos = wallet.state.nonSlpUtxos; | ||||
const xecUtxos = slpBalancesAndUtxos.nonSlpUtxos; | const tokenUtxos = wallet.state.slpUtxos; | ||||
const tokenUtxos = slpBalancesAndUtxos.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 ( | if (!xecUtxos || xecUtxos.length === 0) { | ||||
!slpBalancesAndUtxos || | |||||
!slpBalancesAndUtxos.nonSlpUtxos || | |||||
slpBalancesAndUtxos.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', | ||||
▲ Show 20 Lines • Show All 311 Lines • Show Last 20 Lines |