From 5581ec796b510414345a9c7f9c1a4c13520d678a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Sim=C3=A3o?= Date: Wed, 26 Jul 2023 10:29:40 +0100 Subject: [PATCH] feat: add talisman --- package.json | 1 + src/App.tsx | 14 ++++++++++++++ src/lib/wallet/WalletProvider.tsx | 16 ++++++++++++++++ yarn.lock | 5 +++++ 4 files changed, 36 insertions(+) create mode 100644 src/lib/wallet/WalletProvider.tsx diff --git a/package.json b/package.json index 68cca2c34e..5fa870a700 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "@react-stately/tooltip": "^3.2.3", "@react-stately/tree": "^3.4.1", "@tailwindcss/forms": "^0.3.2", + "@talismn/connect-wallets": "^1.2.3", "big.js": "^6.1.1", "chart.js": "^2.9.4", "clsx": "^1.1.1", diff --git a/src/App.tsx b/src/App.tsx index bdb0eb3127..0e9f1ae963 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,6 +2,7 @@ import './i18n'; import { FaucetClient, SecurityStatusCode } from '@interlay/interbtc-api'; import { Keyring } from '@polkadot/keyring'; +import { getWallets } from '@talismn/connect-wallets'; import * as React from 'react'; import { useErrorHandler, withErrorBoundary } from 'react-error-boundary'; import { useQuery } from 'react-query'; @@ -91,6 +92,19 @@ const App = (): JSX.Element => { ); useErrorHandler(vaultsError); + // get an array of wallets which are installed + const installedWallets = getWallets().filter((wallet) => wallet.installed); + + console.log(getWallets()); + + // get talisman from the array of installed wallets + const talismanWallet = installedWallets.find((wallet) => wallet.extensionName === 'subwallet'); + + // enable the wallet + if (talismanWallet) { + console.log(talismanWallet.enable('myCoolDapp')); + } + // Initializes data on app bootstrap React.useEffect(() => { if (!dispatch) return; diff --git a/src/lib/wallet/WalletProvider.tsx b/src/lib/wallet/WalletProvider.tsx new file mode 100644 index 0000000000..7bd5b7c71d --- /dev/null +++ b/src/lib/wallet/WalletProvider.tsx @@ -0,0 +1,16 @@ +import React from 'react'; + +// eslint-disable-next-line @typescript-eslint/ban-types +type WalletConfig = {}; + +const defaultContext: WalletConfig = {} as WalletConfig; + +const WalletContext = React.createContext(defaultContext); + +const useWallet = (): WalletConfig => React.useContext(WalletContext); + +const WalletProvider: React.FC = ({ children }) => { + return {children}; +}; + +export { useWallet, WalletContext, WalletProvider }; diff --git a/yarn.lock b/yarn.lock index fae3fcd531..50836acb9a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5887,6 +5887,11 @@ resolve "^1.20.0" tmp "^0.2.1" +"@talismn/connect-wallets@^1.2.3": + version "1.2.3" + resolved "https://registry.yarnpkg.com/@talismn/connect-wallets/-/connect-wallets-1.2.3.tgz#4aa91f2c554d692e9f49472f74dcc96fca319df5" + integrity sha512-6hLYeDnMjrlsNLF6a9e7ngxKMkKW3uTC2IbBjtTPq9fxA1VvApmxR8egboPzU7sgFQEuUFP36KN1hFAtfRIVhw== + "@testing-library/dom@^8.0.0": version "8.20.0" resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.20.0.tgz#914aa862cef0f5e89b98cc48e3445c4c921010f6"