transaction-confirm

transaction-confirm helps dapp to handle the event of newly created transactions. With transaction-confirm, dapp developers will be able to:

  • save and update transaction detail in browser’s local storage

  • display transaction confirm status on the transaction modal

  • display notification message if transaction’s status was changed


Get Started

Installation

  • npm i

Run

  • npm run start

Build

  • npm run build


openTransModal

Display the transaction modal with step info

Parameters

Argument

Description

Type

stepInfo

The info to display in the modal

object

tronscanLink

The tronscan site for <a> redirection

string

stepInfo:

Argument

Description

Type

step

1: Waiting for customer response 2: Transaction accepted 3: Transaction rejected

int

txId

Transaction id of the transaction(if any)

string

customObj

Additional configuration of the modal

object

customObj:

Argument

Description

Type

title

Modal title

string

lang

Language of modal content: en/zh

string

wait_confirm

Custom message for the waiting for confirmation scenario

string

confirm_wallet

Custom message to ask customer to confirm the transaction in the wallet

string

submitted

Custom message for the transaction submitted scenario

string

view_on_tronscan

Custom message for the tronscan link

string

cancelled

Custom message for the transaction cancelled scenario

string

Example

openTransModal(
   {step: 2, txId: 'xxxxxx', customObj: {title: 'Send TRX success'}},
   'https://tronscan.org/#/'
);

addNewTransactionToList

Add new transaction to the pending transaction list in the browser’s local storage

Parameters

Argument

Description

Type

tx

The transaction object returned from tronweb

string

customObj

Custom data to be saved with the transaction in the pending transaciton list

any

saveAmount

Maximum capacity of the list

int

tronweb

Tronweb instance

any

Example

const tx = await sendTrx(
  'TBHHa5Z6WQ1cRcgUhdvqdW4f728f2fiJmF',
  1000000
);

addNewTransactionToList(tx.txid, {title: 'Send 1 TRX to somewhere'}, 10);

updateTransactionInList

Update an existing transaction in the pending transaction list in localStorage

Parameters

Argument

Description

Type

record

The transaction object to be updated

object

tronweb

The Tronweb instance

object

Example

// Update transaction content
transaction.showPending = false

// And save to the pending transaction list
updateTransactionInList(transaction)

logTransaction

Update transaction status and display notification message

Parameters

Argument

Description

Type

record

Transaction object to be updated

object

status

New status: 1/2/3

int

lang

Language of the notifaction message content

string

Example

logTransaction(transaction, 2)

getDescription

Get transaction description dom object

Parameters

Argument

Description

Type

type

Transaction status value

int

item

Transaction object

object

text

The status text display on the dom object

string

Response

The dom object

<div class="transaction_notify__nhkKG">
  <span>
    <a href="https://tronscan.io/#/transaction/xxxx" target="_blank">
      View on TRONSCAN
    </a>
    <a>
      Pending
    </a>
  </span>
  <span class="trans-btn-tip">
    Pending
  </span>
</div>

Example

getDescription(status, item, description)

getTransactionInfo

Get the latest status of a transaction info

Parameters

Argument

Description

Type

txid

Transaction id

string

tronweb

Tronweb instance

object

Response

The promise of tronWeb.trx.getConfirmedTransaction response

Example

getTransactionInfo(xxxxxx)
  .then(response => {
    console.log(response)
  })

checkPendingTransaction

Check the status of each pending transaction in the transaction list from the browser’s local storage, and use getTransactionInfo to check the latest status of each pending transaction. If the status was updated, call logTransaction to update and save the transaction.

Parameters

Argument

Description

Type

tronweb

Tronweb instance

object

Example

checkPendingTransactions()

startPendingTransactionCheck

Constantly check the status of each pending transactions

Parameters

Argument

Description

Type

milliseconds

The interval of each checkPendingTransaction call

number

tronweb

Tronweb instance

object

Example

startPendingTransactionCheck(3000)