Skip to content

Commit b347c01

Browse files
committed
handling all requests to dapp connector
1 parent 0ed1f87 commit b347c01

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/components/tabs/subtabs/tokenTab.js

+31-31
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const TokenTab = () => {
7474
</div>
7575
)
7676
} else {
77-
return (<></>)
77+
return <></>
7878
}
7979
}
8080

@@ -106,42 +106,42 @@ const TokenTab = () => {
106106
console.debug(`[dApp][Tokens_Tab][mint] changeAddress -> ${changeAddress}`)
107107

108108
const wasmChangeAddress = getAddressFromBytes(wasm, changeAddress)
109-
const usedAddresses = await api?.getUsedAddresses()
110-
const usedAddress = getAddressFromBytes(wasm, usedAddresses[0])
111-
const pubkeyHash = getPubKeyHash(wasm, usedAddress)
112-
const wasmNativeScript = getNativeScript(wasm, pubkeyHash)
113-
114-
// magic should happen here
115-
txBuilder.add_mint_asset_and_output_min_required_coin(
116-
wasmNativeScript,
117-
getAssetName(wasm, clearTokenName),
118-
quantityInt,
119-
getTransactionOutputBuilder(wasm, wasmChangeAddress),
120-
)
121-
122-
console.debug(`[dApp][Tokens_Tab][mint] getting UTxOs`)
123-
const hexInputUtxos = await api?.getUtxos()
124-
125-
console.debug(`[dApp][Tokens_Tab][mint] preparing wasmUTxOs`)
126-
const wasmUtxos = wasm.TransactionUnspentOutputs.new()
127-
for (const hexInputUtxo of hexInputUtxos) {
128-
const wasmUtxo = wasm.TransactionUnspentOutput.from_bytes(hexToBytes(hexInputUtxo))
129-
wasmUtxos.add(wasmUtxo)
130-
}
109+
try {
110+
const usedAddresses = await api?.getUsedAddresses()
111+
const usedAddress = getAddressFromBytes(wasm, usedAddresses[0])
112+
const pubkeyHash = getPubKeyHash(wasm, usedAddress)
113+
const wasmNativeScript = getNativeScript(wasm, pubkeyHash)
114+
115+
// magic should happen here
116+
txBuilder.add_mint_asset_and_output_min_required_coin(
117+
wasmNativeScript,
118+
getAssetName(wasm, clearTokenName),
119+
quantityInt,
120+
getTransactionOutputBuilder(wasm, wasmChangeAddress),
121+
)
131122

132-
console.debug(`[dApp][Tokens_Tab][mint] adding inputs`)
133-
txBuilder.add_inputs_from(wasmUtxos, wasm.CoinSelectionStrategyCIP2.LargestFirstMultiAsset)
134-
txBuilder.add_required_signer(pubkeyHash)
135-
txBuilder.add_change_if_needed(wasmChangeAddress)
123+
console.debug(`[dApp][Tokens_Tab][mint] getting UTxOs`)
124+
const hexInputUtxos = await api?.getUtxos()
136125

137-
const unsignedTransactionHex = bytesToHex(txBuilder.build_tx().to_bytes())
138-
console.debug(`[dApp][Tokens_Tab][mint] signing the tx`)
126+
console.debug(`[dApp][Tokens_Tab][mint] preparing wasmUTxOs`)
127+
const wasmUtxos = wasm.TransactionUnspentOutputs.new()
128+
for (const hexInputUtxo of hexInputUtxos) {
129+
const wasmUtxo = wasm.TransactionUnspentOutput.from_bytes(hexToBytes(hexInputUtxo))
130+
wasmUtxos.add(wasmUtxo)
131+
}
132+
133+
console.debug(`[dApp][Tokens_Tab][mint] adding inputs`)
134+
txBuilder.add_inputs_from(wasmUtxos, wasm.CoinSelectionStrategyCIP2.LargestFirstMultiAsset)
135+
txBuilder.add_required_signer(pubkeyHash)
136+
txBuilder.add_change_if_needed(wasmChangeAddress)
137+
138+
const unsignedTransactionHex = bytesToHex(txBuilder.build_tx().to_bytes())
139+
console.debug(`[dApp][Tokens_Tab][mint] signing the tx`)
139140

140-
try {
141141
const transactionHex = await api?.signTx({tx: unsignedTransactionHex, returnTx: true})
142142
console.debug(`[dApp][Tokens_Tab][mint] TransactionHex: ${transactionHex}`)
143143
const txId = await api.submitTx(transactionHex)
144-
console.debug(`[dApp][Tokens_Tab][mint] Transaction successfully submitted: ${txId}`)
144+
console.log(`[dApp][Tokens_Tab][mint] Transaction successfully submitted: ${txId}`)
145145
} catch (error) {
146146
handleError(error)
147147
console.error(error)

0 commit comments

Comments
 (0)