vechain / connex

The mono-repo contains libraries to help build dApps for VeChain.
https://docs.vechain.org/developer-resources/sdks-and-providers/connex
GNU Lesser General Public License v3.0
86 stars 3.58k forks source link

Simplify wallet selection #153

Closed libotony closed 1 year ago

libotony commented 1 year ago

This PR changes the constructor options to:

/** options for creating Connex object */
export type Options = {
    /** the base url of the thor node's thorREST API */
    node: string
    /**
     * the expected network of the node url. defaults to 'main' if omitted.
     * if it does not match with the actual network of the node url points to,
     * all subsequent request will fail.
     */
    network?: 'main' | 'test' | Connex.Thor.Block
    /** 
     * designated wallet to connect, Sync, Sync2 or VeWorldExtension supported, Sync2 if omitted.
     */
    signer?: 'sync' | 'sync2' | 'veworldextension'
}

Which makes dApp developers explicitly declare the signer they wish to connect. Sync, Sync2, VeWorldExteion.

const nodeURL = 'https://...'
const connex = new Connex({node: nodeURL, network: 'main', signer: 'sync2'}) // Sync2
const connex = new Connex({node: nodeURL, network: 'main', signer: 'veworldextension'}) // VeWorldExtension
const connex = new Connex({node: nodeURL, network: 'main'}) // sync2 if omit signer option

const vendor = new Connex.Vendor('test', 'sync') // sync or vechainthor mobile wallet

This PR also introduced Connex.Thor class for read-only functions, which allows dApps delay the time of interacting with wallets.

const thor = new Connex.Thor({node: 'https://...', network: 'main'})
// .... some reading options
const vendor = new Connex.Vendor('main', 'sync2')
vendor.sign('tx', ...)