1.0.4 • Published 1 month ago

@radixdlt/connect-button v1.0.4

Weekly downloads
-
License
SEE LICENSE IN RA...
Repository
github
Last release
1 month ago

License

The √ Connect Button is a framework agnostic web component to help developers connect users and their Radix Wallet to their dApps.

It appears as a consistent, Radix-branded UI element that helps users identify your dApp website as a Radix dApp and compatible with the Radix Wallet – and it automatically provides a consistent user experience for users to connect with their wallet and see the current status of the connection between dApp and Radix Wallet.

The √ Connect Button API acts as a wrapper to the Wallet SDK and exposes its methods while adding additional methods.

Installation

Using NPM

npm install @radixdlt/connect-button

Using Yarn

yarn add @radixdlt/connect-button

Usage

Getting started

Add the <radix-connect-button /> element in your HTML code and call the configuration function.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script type="module" src="/bundle.js"></script>
  </head>
  <body>
    <radix-connect-button />
  </body>
</html>

Configuration

The connect button needs to be configured before use.

configure(input: ConfigurationInput) => RadixConnectButtonApi

import {
  configure,
  requestBuilder,
  requestItem,
} from '@radixdlt/connect-button'

configure({
  dAppId: 'dashboard',
  networkId: 0x01,
  onConnect: ({ setState, getWalletData }) => {
    getWalletData(
      requestBuilder(requestItem.oneTimeAccounts.withoutProofOfOwnership(1))
    ).map(({ oneTimeAccounts }) => {
      setState({ connected: true })
    })
  },
  onDisconnect: ({ setState }) => {
    setState({ connected: false })
  },
})
type ConfigurationInput = {
  dAppId: string
  networkId?: number
  initialState?: Partial<ButtonState>
  onConnect: (api: RadixConnectButtonApi) => void
  onDisconnect: (api: RadixConnectButtonApi) => void
  onCancel?: () => void
  onDestroy?: () => void
}
  • requires dAppId - Specifies the dApp that is interacting with the wallet. Used in dApp verification process on the wallet side.
  • optional networkId - Specifies which network to use, defaults to mainnet (0x01)
  • optional initialState - Forces initial connected and / or loading state for button
  • requires onConnect - Callback that triggers when user clicks connect now button
  • requires onDisconnect - Callback that triggers when user clicks disconnect wallet button
  • optional onCancel - Callback that triggers when user cancels connect request
  • optional onDestroy - Callback that triggers when button is removed from the DOM. Useful for cleaning up registered event listeners and subscriptions.

API

type RadixConnectButtonApi = {
  getWalletData: WalletSdkType['request']
  sendTransaction: WalletSdkType['sendTransaction']
  setState: (
    input: Partial<{
      connected: boolean
      loading: boolean
    }>
  ) => void
  destroy: () => void
  onConnect$: Observable<void>
}
  • getWalletData – uses wallet SDK request method
  • sendTransaction – uses wallet SDK sendTransaction method
  • setState – Sets the state of the button
  • destroy – Cleanup function to destroy the configuration instance
  • onConnect$ – Observable that emits when the user clicks on the connect button

Examples

1.0.5-dev.1

1 month ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.0-alpha.6

4 months ago

1.0.0-alpha.5

4 months ago

1.0.3-alpha.1

4 months ago

1.0.3-alpha.2

4 months ago

1.0.2

4 months ago

0.14.0-alpha.5

8 months ago

0.14.0-alpha.4

8 months ago

0.14.0-alpha.3

8 months ago

1.0.0-alpha.4

6 months ago

0.14.0-alpha.2

8 months ago

1.0.0-alpha.3

6 months ago

1.0.0-alpha.2

7 months ago

1.0.0-alpha.1

8 months ago

0.13.0

9 months ago

0.13.1

9 months ago

0.14.0-alpha.1

8 months ago

0.13.2

9 months ago

0.13.3

9 months ago

0.13.4

8 months ago

0.13.3-alpha.2

8 months ago

0.13.1-alpha.12

9 months ago

0.13.1-alpha.11

9 months ago

0.13.1-alpha.10

9 months ago

0.13.3-alpha.1

9 months ago

0.13.1-alpha.16

9 months ago

0.13.1-alpha.15

9 months ago

0.13.1-alpha.14

9 months ago

0.13.1-alpha.13

9 months ago

0.14.0

8 months ago

0.13.2-alpha.3

9 months ago

0.13.2-alpha.2

9 months ago

0.13.2-alpha.1

9 months ago

1.0.1

6 months ago

1.0.0

7 months ago

0.13.4-alpha.1

8 months ago

0.13.0-alpha.12

9 months ago

0.13.0-alpha.13

9 months ago

0.13.0-alpha.14

9 months ago

0.13.0-alpha.15

9 months ago

0.13.0-alpha.10

9 months ago

0.13.0-alpha.11

9 months ago

0.13.1-alpha.5

9 months ago

0.13.1-alpha.4

9 months ago

0.13.1-alpha.3

9 months ago

0.13.1-alpha.2

9 months ago

0.13.1-alpha.9

9 months ago

0.13.1-alpha.8

9 months ago

0.13.1-alpha.7

9 months ago

0.13.1-alpha.6

9 months ago

0.15.0-alpha.3

8 months ago

0.13.1-alpha.1

9 months ago

0.15.0-alpha.1

8 months ago

0.15.0-alpha.2

8 months ago

0.13.0-alpha.9

9 months ago

0.13.0-alpha.8

10 months ago

0.13.0-alpha.7

10 months ago

0.13.0-alpha.6

10 months ago

0.13.0-alpha.5

10 months ago

0.13.0-alpha.4

10 months ago

0.13.0-alpha.3

10 months ago

0.13.0-alpha.2

10 months ago

0.12.0-alpha.1

1 year ago

0.12.0-alpha.2

1 year ago

0.12.0-alpha.3

1 year ago

0.12.0-alpha.4

1 year ago

0.12.0

1 year ago

0.13.0-alpha.1

1 year ago

0.11.0

1 year ago

0.11.0-alpha.6

1 year ago

0.11.0-alpha.5

1 year ago

0.11.0-alpha.8

1 year ago

0.11.0-alpha.7

1 year ago

0.11.0-alpha.9

1 year ago

0.11.0-alpha.2

1 year ago

0.11.0-alpha.1

1 year ago

0.11.0-alpha.4

1 year ago

0.11.0-alpha.3

1 year ago

0.10.1

1 year ago

0.10.0

1 year ago

0.9.1

1 year ago

0.9.0

1 year ago

0.8.1

1 year ago

0.8.0

1 year ago

0.7.0

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago