Skip to content

Commit

Permalink
chore: isolate supported wallets config
Browse files Browse the repository at this point in the history
  • Loading branch information
JayJay1024 committed Jun 14, 2022
1 parent 870a6ce commit abd91ce
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 43 deletions.
1 change: 1 addition & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './network';
export * from './theme';
export * from './validate-msg';
export * from './api';
export * from './wallet';
39 changes: 39 additions & 0 deletions src/config/wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Wallet } from '../model';

const injecteds = window.injectedWeb3;

export const supportedWallets: Wallet[] = [
{
...(injecteds['polkadot-js'] ?? []),
extensionName: 'polkadot-js',
title: 'Polkadot{.js}',
installUrl: 'https://polkadot.js.org/extension/',
installed: !!injecteds['polkadot-js'],
logo: {
src: '/image/wallet/polkadot-js.svg',
alt: 'Polkadotjs Logo',
},
},
{
...(injecteds['talisman'] ?? {}),
extensionName: 'talisman',
title: 'Talisman',
installUrl: 'https://chrome.google.com/webstore/detail/talisman-wallet/fijngjgcjhjmmpcmkeiomlglpeiijkld',
installed: !!injecteds['talisman'],
logo: {
src: '/image/wallet/talisman.svg',
alt: 'Talisman Logo',
},
},
// {
// ...(injecteds['subwallet-js'] ?? {}),
// extensionName: 'subwallet-js',
// title: 'SubWallet',
// installUrl: 'https://subwallet.app/download.html',
// installed: !!injecteds['subwallet-js'],
// logo: {
// src: '/image/wallet/subwallet-js.svg',
// alt: 'Subwallet Logo',
// },
// },
];
45 changes: 2 additions & 43 deletions src/providers/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { accounts as accountsObs } from '@polkadot/ui-keyring/observable/account
import type { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import { from } from 'rxjs';
import type { Wallet, Account, WalletSource } from '../model';
import { DAPP_NAME, LOCAL_SOURCE, SEARCH_PARAMS_SOURCE } from '../config';
import { DAPP_NAME, LOCAL_SOURCE, SEARCH_PARAMS_SOURCE, supportedWallets } from '../config';
import { convertToSS58, isValidAddress, updateStorage, readStorage } from '../utils';
import { useApi } from '../hooks';

Expand Down Expand Up @@ -32,11 +32,10 @@ export const WalletProvider = ({ children }: PropsWithChildren<unknown>) => {
const [signer, setSigner] = useState<InjectedSigner | null>();
const [accounts, setAccounts] = useState<Account[]>([]);
const [walletToUse, setWalletToUse] = useState<Wallet | null>();
const [supportedWallets, setSupportedWallets] = useState<Wallet[]>([]);

const getWalletBySource = useCallback(
(source: WalletSource) => supportedWallets.find((item) => item.extensionName === source),
[supportedWallets]
[]
);

const connectWallet = useCallback(
Expand Down Expand Up @@ -147,46 +146,6 @@ export const WalletProvider = ({ children }: PropsWithChildren<unknown>) => {
return () => sub$$();
}, [walletToUse, network.ss58Prefix, api, accountsObsData]);

useEffect(() => {
const injecteds = window.injectedWeb3;

setSupportedWallets([
{
...(injecteds['polkadot-js'] ?? []),
extensionName: 'polkadot-js',
title: 'Polkadot{.js}',
installUrl: 'https://polkadot.js.org/extension/',
installed: !!injecteds['polkadot-js'],
logo: {
src: '/image/wallet/polkadot-js.svg',
alt: 'Polkadotjs Logo',
},
},
{
...(injecteds['talisman'] ?? {}),
extensionName: 'talisman',
title: 'Talisman',
installUrl: 'https://chrome.google.com/webstore/detail/talisman-wallet/fijngjgcjhjmmpcmkeiomlglpeiijkld',
installed: !!injecteds['talisman'],
logo: {
src: '/image/wallet/talisman.svg',
alt: 'Talisman Logo',
},
},
// {
// ...(injecteds['subwallet-js'] ?? {}),
// extensionName: 'subwallet-js',
// title: 'SubWallet',
// installUrl: 'https://subwallet.app/download.html',
// installed: !!injecteds['subwallet-js'],
// logo: {
// src: '/image/wallet/subwallet-js.svg',
// alt: 'Subwallet Logo',
// },
// },
]);
}, []);

useEffect(() => {
connectWallet(readStorage().activeWallet);
}, [connectWallet]);
Expand Down

0 comments on commit abd91ce

Please sign in to comment.