Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Xdefi Wallet Context Provider #1

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

Da-Colon
Copy link

@Da-Colon Da-Colon commented Jun 9, 2022

Overview

Creates a context wrapper that exposes xdefi bitcoin and litecoin providers when xdefi wallet is connected.

Notes

There are three states that this provider will be in

XDEFI_CONNECTED

Xdefi wallet is propoerly connected.

returned state

ethereumWallet: HDWallet
xfiBitcoinProvider: IXfiBitcoinProvider
xfiLitecoinProvider: IXfiLitecoinProvider

XDEFI_NOT_CONNECTED

A different wallet is connected. in this case the ethereum wallet is set leaving bitcoin and litecoin providers null

ethereumWallet: HDWallet
xfiBitcoinProvider: null
xfiLitecoinProvider: null

NOT_CONNECTED

No Wallet is connected (default state)

ethereumWallet: null,
xfiBitcoinProvider: null,
xfiLitecoinProvider: null,

USUAGE

import the Provider component and wrap

import { XDEFIWalletProvider } from 'context/XDEFIProvider/XDEFIWalletProvider'

function Component() {
  return (
    <XDEFIWalletProvider>
      <ChildComponent>
    </XDEFIWalletProvider>
  )
}

and easily use the custom hook in children

import { useXdefiProvider } from 'context/XDEFIProvider/hooks/useXDEFIProvider'

function ChildComponent() {
  const {
    state: { xfiBitcoinProvider, xfiLitecoinProvider, ethereumWallet, isWalletLoading },
  } = useXDEFIProvider()


  return (
    ...
  )
}

- if xdefi wallet is connected exposes a bitcoin and litecoin provider
- creates a context provider to pass wrapped wallet provider
@Da-Colon Da-Colon added the enhancement New feature or request label Jun 9, 2022
@Da-Colon Da-Colon requested a review from cmccand June 9, 2022 17:31
@Da-Colon Da-Colon self-assigned this Jun 9, 2022
Comment on lines +12 to +27
export interface IXfiBitcoinProvider {
accounts: string[]
chainId: string
network: string
request: (e: { method: string; params: any[] }, cb: AnyFunction) => Promise<any>
signTransaction: (e: any) => Promise<void>
transfer: (e: any) => Promise<void>
}

export interface IXfiLitecoinProvider {
accounts: string[]
chainId: string
network: string
request: (e: { method: string; params: any[] }, cb: AnyFunction) => void
transfer: (e: any) => void
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is set up so that when a XDEFI wallet is connected then it will grab the accounts of the needed wallets, in this case litecoin and bitcoin and gather some general information about the connection in a 'provider' object.

For bitcoin it exposes the request, signTransaction, and transfer methods.
https://sdk.xdefi.io/docs/HEAD/bitcoin.html

For litecoin it exposes the request and transfer methods.
https://sdk.xdefi.io/docs/HEAD/litecoin.html

These will allow you to interact with these chains

Comment on lines +5 to +10
export interface InitialState {
ethereumWallet: HDWallet | null
xfiBitcoinProvider: IXfiBitcoinProvider | null
xfiLitecoinProvider: IXfiLitecoinProvider | null
isWalletLoading: boolean
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state interface that is provided by the useXDEFIProvider hook.

The etereumWallet is the Wallet created when connecting via Shapeshift's interface. this is for easy access to the other wallets when connected to any other ethereum wallet.

@Da-Colon Da-Colon marked this pull request as ready for review June 9, 2022 17:39
@Da-Colon Da-Colon changed the title adds xdefi provider wrapper adds xdefi provider Context Provider Jun 9, 2022
@Da-Colon Da-Colon changed the title adds xdefi provider Context Provider adds xdefi wallet Context Provider Jun 9, 2022
@Da-Colon Da-Colon changed the title adds xdefi wallet Context Provider Xdefi Wallet Context Provider Jun 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant