Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some types + add start to root #1

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"packages/*"
],
"scripts": {
"build:core": "cd packages/core && yarn build",
"build:react": "cd packages/react && yarn build",
"start": "yarn build:core && yarn build:react && cd packages/react-ui && yarn start",
"format": "prettier --write \"./src/**/*.{ts,tsx}\""
}
}
39 changes: 21 additions & 18 deletions packages/react/src/contexts/DotsamaWalletsContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext, useState, useMemo, useCallback } from 'react';
import { getExtensions, ExtensionInfo, BasicExtensionInfo } from '@dotsama-wallets/core';
import { getExtensions, DotsamaWallet, DotsamaWalletBasic, ExtensionEnabler } from '@dotsama-wallets/core';
import { Injected, InjectedAccount } from '@polkadot/extension-inject/types';

interface DotsamaWalletsContextProviderProps {
Expand All @@ -8,31 +8,34 @@ interface DotsamaWalletsContextProviderProps {

interface DotsamaWalletsContextProps {
setupWallets: () => void;
connectToExtension: (appName: string, extension: ExtensionInfo) => Promise<{ injectedExtension: Injected, accounts: InjectedAccount[] }>;
extensions: ExtensionInfo[];
otherExtensions: BasicExtensionInfo[];
connectToExtension: (appName: string, extension: DotsamaWallet<ExtensionEnabler>) => Promise<{ injectedExtension: Injected; accounts: InjectedAccount[] }>;
extensions: DotsamaWallet<ExtensionEnabler>[];
otherExtensions: DotsamaWalletBasic<ExtensionEnabler>[];
}

export const DotsamaWalletsContext = createContext<DotsamaWalletsContextProps>({
setupWallets: () => {},
connectToExtension: async () => ({ injectedExtension: {} as Injected, accounts: []}),
connectToExtension: async () => ({ injectedExtension: {} as Injected, accounts: [] }),
extensions: [],
otherExtensions: [],
});

export const DotsamaWalletsContextProvider = ({ children }: DotsamaWalletsContextProviderProps) => {
const [extensions, setExtensions] = useState<ExtensionInfo[]>([]);
const [otherExtensions, setOtherExtensions] = useState<BasicExtensionInfo[]>([]);

const connectToExtension = useCallback(async (appName: string, extension: ExtensionInfo) => {
// TODO extension connection should be separate from getting accounts, but for that will need ping functionality to get isConnected status
// currently we don't have that yet
// add try catches
const injectedExtension = await extension.enable(appName);
const accounts = await injectedExtension.accounts.get();

return { injectedExtension, accounts };
}, [extensions, otherExtensions]);
const [extensions, setExtensions] = useState<DotsamaWallet<ExtensionEnabler>[]>([]);
const [otherExtensions, setOtherExtensions] = useState<DotsamaWalletBasic<ExtensionEnabler>[]>([]);

const connectToExtension = useCallback(
async (appName: string, extension: DotsamaWallet<ExtensionEnabler>) => {
// TODO extension connection should be separate from getting accounts, but for that will need ping functionality to get isConnected status
// currently we don't have that yet
// add try catches
const injectedExtension = await extension.enable(appName);
const accounts = await injectedExtension.accounts.get();

return { injectedExtension, accounts };
},
[extensions, otherExtensions],
);

// initializer, gets all the extensions
const setupWallets = () => {
Expand All @@ -41,7 +44,7 @@ export const DotsamaWalletsContextProvider = ({ children }: DotsamaWalletsContex

setExtensions([...knownExtensions]); // TODO: potentially can be [...knownExtensions, walletConnect]
setOtherExtensions([...otherExtensions]);
}
};

const contextData = useMemo(
() => ({
Expand Down