Optimistic UI

Overview

As explained in the architecture section, the entire Living Assets Layer-2 is synchronized with the underlying blockchain (e.g. Polygon) every 15 minutes. After each sync all successfully paid transfers are consolidated, and the Layer-1 itself can be queried to certify the ownership of all assets.

Clients of the network are free to implement their preferred UX flow. The following are common practices in web3 applications.

Some applications may choose to show transfers as, e.g. incoming, during the period of time, of at most 15 minutes, during which the transfer is accepted in the Layer-2, but not yet synced with the Layer-1.

Others may implement a more optimistic flow, whereby the asset is shown as already transferred, perhaps warning the users that it can be put for sale again in a few minutes.

During this period of time, the trading API will return that the asset is in ASSET_TRANSFERRING state.

The Layer-2 nodes are the ultimate source of truth, and will produce the corresponding transfer events after every Layer-1 sync is completed.

Optimistic Request

While querying for payments in ASSET_TRANSFERRING state can be used to determine assets that are about to be synced with the Layer-1, the following request can be more convenient.

getUserAssets is a query that integrates the optimistic flow. It will return all assets owned by the provided web3Address, including:

  • assets that are still in ASSET_TRANSFERRINGstate,

  • assets for which a payment is in the process of:

    • in fiat flows, being confirmed by the 3rd party Fiat payments provider;

    • in crypto flows, waiting for enough number of confirmations by the blockchain.

query{
    getUserAssets(universe: 0, web3Address: "0xc25b879b3Ea73A487F3e189f32B1d42315aeE883" ){
        nodes {
          assetid
          state      
        }
    }
  }

All possible values for state are described in the State Machine.

When using the Payment Gateway, the following considerations may be useful:

  • As soon as a user fills in the required data, and clicks the PAY button, the getUserAssets query already returns the asset as (optimistically) belonging to the user, even if the state is not in ASSET_TRANSFERRING yet. The redirect button is not enabled until the payment is confirmed.

  • As soon as the payment is confirmed (either in fiat or crypto flows), the state moves to ASSET_TRANSFERRINGand the redirect button is enabled.

Last updated

freeverse.io