Skip to content

Commit

Permalink
api version 4.15.2 => 6.0.4 & .json -.wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
freepoi committed Nov 22, 2021
1 parent ffde48c commit 11dd9a9
Show file tree
Hide file tree
Showing 25 changed files with 2,727 additions and 1,909 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "europa-ui",
"version": "0.3.32",
"version": "0.3.33",
"main": "main.js",
"private": true,
"description": "An UI used for deploying and testing contracts on the Europa node embedded",
"dependencies": {
"@polkadot/api": "^4.15.2-2",
"@polkadot/api-contract": "^4.15.2-2",
"@polkadot/react-identicon": "^0.81.2-0",
"@polkadot/types": "^4.15.2-2",
"@polkadot/ui-keyring": "^0.81.2-0",
"@polkadot/ui-settings": "^0.81.2-0",
"@polkadot/api": "6.0.4-1",
"@polkadot/api-contract": "6.0.4-1",
"@polkadot/react-identicon": "0.85.4",
"@polkadot/types": "6.0.4-1",
"@polkadot/ui-keyring": "0.85.4",
"@polkadot/ui-settings": "0.85.4",
"antd": "^4.15.4",
"i18next": "^20.3.0",
"i18next-browser-languagedetector": "^6.1.1",
Expand Down
30 changes: 14 additions & 16 deletions src/core/hook/useRedspotContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface RedspotContract {
}

export const useRedspotContracts = (redspotProjects: string[]) => {
const [ respotContracts, setContracts ] = useState<RedspotContract[]>([]);
const [respotContracts, setContracts] = useState<RedspotContract[]>([]);

useEffect(() => {
if (!requireModule.isElectron) {
Expand All @@ -26,13 +26,15 @@ export const useRedspotContracts = (redspotProjects: string[]) => {

const readObservables = redspotProjects
.map(projectPath => path.resolve(projectPath, '../artifacts'))
.map((dirPath) => from(fs.promises.readdir(dirPath))
.pipe(
.map(dirPath =>
from(fs.promises.readdir(dirPath)).pipe(
map((files: string[]): Observable<RedspotContract>[] =>
files
.filter(name => name.endsWith('.contract'))
.map(async (file) => {
const json = (await fs.promises.readFile(path.resolve(dirPath, file))).toString();
.map(async file => {
const json = (
await fs.promises.readFile(path.resolve(dirPath, file))
).toString();
const abi = new Abi(json);
const name = abi.project?.contract?.name?.toString();
const hash = abi.project?.source?.wasmHash?.toString();
Expand All @@ -48,24 +50,20 @@ export const useRedspotContracts = (redspotProjects: string[]) => {
.map(redspotContract => from(redspotContract))
),
mergeMap(redspotProjects => zip(...redspotProjects)),
catchError((_): Observable<RedspotContract[]> => of([])),
catchError((_): Observable<RedspotContract[]> => of([]))
)
);

const sub = zip(...readObservables).pipe(
map(results =>
results.reduce(
(all, curr) => all.concat(curr), []
)
),
).subscribe(contracts => {
setContracts(contracts);
});
const sub = zip(...readObservables)
.pipe(map(results => results.reduce((all, curr) => all.concat(curr), [])))
.subscribe(contracts => {
setContracts(contracts);
});

return () => sub.unsubscribe();
}, [redspotProjects]);

return {
redspotContracts: respotContracts,
};
};
};
127 changes: 79 additions & 48 deletions src/core/provider/accounts.provider.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import React, { Context, useCallback, useContext, useEffect, useState } from 'react';
import { of, zip } from 'rxjs';
import { catchError, map, mergeMap } from 'rxjs/operators';
import React, {
Context,
useCallback,
useContext,
useEffect,
useState,
} from 'react';
import { filter, skip, catchError, map, mergeMap, of, zip } from 'rxjs';
import type { KeyringPair$Meta } from '@polkadot/keyring/types';
import type { KeypairType } from '@polkadot/util-crypto/types';
import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
import { formatBalance } from '@polkadot/util';
import { ApiContext } from './api.provider';
import { BusContext } from './bus.provider';
import { filter, skip } from 'rxjs/operators';

interface AccountJson extends KeyringPair$Meta {
address: string;
Expand All @@ -29,71 +33,98 @@ interface AccountsContextProps {
update: () => void;
}

export const AccountsContext: Context<AccountsContextProps> = React.createContext({}as unknown as AccountsContextProps);
export const AccountsContext: Context<AccountsContextProps> =
React.createContext({} as unknown as AccountsContextProps);


function transformAccounts (accounts: SubjectInfo): AccountJson[] {
return Object.values(accounts).map(({ json: { address, meta }, type }): AccountJson => ({
address,
...meta,
type
}));
function transformAccounts(accounts: SubjectInfo): AccountJson[] {
return Object.values(accounts).map(
({ json: { address, meta }, type }): AccountJson => ({
address,
...meta,
type,
})
);
}

export const AccountsProvider = React.memo(
({ children }: { children: React.ReactNode }): React.ReactElement => {
const { api, tokenDecimal } = useContext(ApiContext);
const { connected$ } = useContext(BusContext);
const [ accounts, setAccounts ] = useState<AccountInfo[]>([]);
const [ signal, updateSignal ] = useState(0);
const [accounts, setAccounts] = useState<AccountInfo[]>([]);
const [signal, updateSignal] = useState(0);

const update = useCallback(() => updateSignal(v => v + 1), [updateSignal]);

useEffect(() => {
const sub = connected$.pipe(
filter(c => !!c),
skip(1),
).subscribe(() => update);

const sub = connected$
.pipe(
filter(c => !!c),
skip(1)
)
.subscribe(() => update);

return () => sub.unsubscribe();
}, [connected$, update]);

useEffect(() => {
if (!api || !api.isReady) {
if (!api || !api.isReady) {
return;
}

const sub = accountsObservable.subject.pipe(
map(accounts => transformAccounts(accounts)),
mergeMap(accounts =>
zip(
...accounts.map(keyringAccount =>
api.derive.balances?.all(keyringAccount.address).pipe(
map(accountInfo => ({
...keyringAccount,
balance: formatBalance(accountInfo.freeBalance.toString(), {}, tokenDecimal),
mnemonic: localStorage.getItem(`mnemonic${keyringAccount.address}`) || '',
})),
catchError(() => of({
...keyringAccount,
balance: '0',
mnemonic: localStorage.getItem(`mnemonic${keyringAccount.address}`) || '',
})),
const sub = accountsObservable.subject
.pipe(
map(accounts => transformAccounts(accounts)),
mergeMap(accounts =>
zip(
...accounts.map(keyringAccount =>
api.derive.balances?.all(keyringAccount.address).pipe(
map(accountInfo => ({
...keyringAccount,
balance: formatBalance(
accountInfo.freeBalance.toString(),
{},
tokenDecimal
),
mnemonic:
localStorage.getItem(
`mnemonic${keyringAccount.address}`
) || '',
})),
catchError(() =>
of({
...keyringAccount,
balance: '0',
mnemonic:
localStorage.getItem(
`mnemonic${keyringAccount.address}`
) || '',
})
)
)
)
)
)
),
).subscribe((accounts) => {
setAccounts(accounts);
console.log('Stored Accounts:', accounts);
}, e => console.log('err', e));

)
.subscribe(
accounts => {
setAccounts(accounts);
console.log('Stored Accounts:', accounts);
},
e => console.log('err', e)
);

return () => sub.unsubscribe();
}, [api, tokenDecimal, signal]);

return <AccountsContext.Provider value={{
accounts,
update,
}}>{children}</AccountsContext.Provider>;
return (
<AccountsContext.Provider
value={{
accounts,
update,
}}
>
{children}
</AccountsContext.Provider>
);
}
);
Loading

0 comments on commit 11dd9a9

Please sign in to comment.