Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sokolova-an committed Dec 19, 2023
1 parent adb2336 commit 1e88a94
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 109 deletions.
2 changes: 1 addition & 1 deletion src/common/chainRegistry/knownChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const kusama: Chain = {
{
url: 'wss://kusama-rpc.dwellir.com',
name: 'Dwellir node',
}
},
],
addressPrefix: 2,
};
Expand Down
49 changes: 9 additions & 40 deletions src/common/extrinsicService/ExtrinsicProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { createContext, PropsWithChildren, useContext, useState } from 'react';
import { createContext, PropsWithChildren, useContext } from 'react';
import { ChainId } from '@common/types';
import { ExtrinsicBuilding, ExtrinsicBuildingOptions } from '@common/extrinsicService/types';
import { Balance } from '@polkadot/types/interfaces';
import { SubmittableResultResult } from '@polkadot/api-base/types/submittable';
import { useExtrinsicService } from '@common/extrinsicService/ExtrinsicService';
import { KeyringPair } from '@polkadot/keyring/types';
import { PasswordPage } from '@/screens/password/Password';

type ExtrinsicProviderContextProps = {
estimateFee: (
Expand All @@ -21,27 +20,13 @@ type ExtrinsicProviderContextProps = {
) => SubmittableResultResult<'promise'>;
};

type ProviderStateAuth = {
kind: 'auth';
resolve: (keyringPair: KeyringPair) => void;
reject: () => void;
};

type ProviderStateContent = {
kind: 'content';
};

type ProviderState = ProviderStateAuth | ProviderStateContent;

const ExtrinsicProviderContext = createContext<ExtrinsicProviderContextProps>({} as ExtrinsicProviderContextProps);

export const FAKE_ACCOUNT_ID = '0x' + '1'.repeat(64);

export const ExtrinsicProvider = ({ children }: PropsWithChildren) => {
const { prepareExtrinsic } = useExtrinsicService();

const [extrinsicState, setExtrinsicState] = useState<ProviderState>({ kind: 'content' });

async function estimateFee(
chainId: ChainId,
building: ExtrinsicBuilding,
Expand All @@ -60,36 +45,20 @@ export const ExtrinsicProvider = ({ children }: PropsWithChildren) => {
): SubmittableResultResult<`promise`> {
const extrinsicPromise = prepareExtrinsic<'promise'>(chainId, building, options);

const keyringPromise = new Promise<KeyringPair>(function (resolve, reject) {
const providerState = { kind: 'auth', resolve, reject } as ProviderStateAuth;
setExtrinsicState(providerState);
});
const keyringPromise = new Promise<KeyringPair>(function () {});

return extrinsicPromise
.then(async (extrinsic) => {
const keyringPair = await keyringPromise;
await extrinsic.signAsync(keyringPair);
keyringPair.lock();
return extrinsicPromise.then(async (extrinsic) => {
const keyringPair = await keyringPromise;
await extrinsic.signAsync(keyringPair);
keyringPair.lock();

return await extrinsic.send();
})
.finally(() => {
setExtrinsicState({ kind: 'content' });
});
}

let content;
switch (extrinsicState.kind) {
case 'content':
content = children;
break;
case 'auth':
content = <PasswordPage onResolve={extrinsicState.resolve} onReject={extrinsicState.reject} />;
return await extrinsic.send();
});
}

return (
<ExtrinsicProviderContext.Provider value={{ estimateFee, submitExtrinsic }}>
{content}
{children}
</ExtrinsicProviderContext.Provider>
);
};
Expand Down
3 changes: 2 additions & 1 deletion src/common/telegram/bot-api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { WebApp } from '@twa-dev/types';
import { HexString } from '../types';
import { getMessageFactory } from './message-factory';
import { WebApp, ITelegramBotApi } from './types';
import { ITelegramBotApi } from './types';

const SUBMIT_WALLET_PATH = '/submit/wallet';

Expand Down
2 changes: 1 addition & 1 deletion src/common/telegram/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HexString } from '@common/types';
import { WebApp } from './types';
import { getTelegramBotApi } from './bot-api';
import { WebApp } from '@twa-dev/types';

export const completeOnboarding = async (publicKey: HexString, webApp: WebApp): Promise<void> => {
const botApi = getTelegramBotApi(webApp);
Expand Down
3 changes: 2 additions & 1 deletion src/common/telegram/message-factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HexString } from '@common/types';
import { WebApp, ITelegramMessageFactory } from './types';
import { ITelegramMessageFactory } from './types';
import { WebApp } from '@twa-dev/types';

export const getMessageFactory = (webApp: WebApp): ITelegramMessageFactory => {
function prepareWalletCreationData(publicKey: HexString): string | null {
Expand Down
29 changes: 11 additions & 18 deletions src/common/utils/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,15 @@ export const updateAssetsBalance = (prevAssets: AssetAccount[], chain: Chain, ba
// );
// }

// async function handleFee() {
// extrinsicService
// .estimateFee(polkadot.chainId, (builder) =>
// builder.addCall(
// builder.api.tx.balances.transferKeepAlive(
// '0xcc23ed33549e874ae7c7653fc5d95b3242dc7df5742664b4809e337a13126433',
// '1234',
// ),
// ),
// )
// .then(
// (fee) => {
// alert('Fee: ' + fee);
// },
// (failure) => {
// alert('Failed to calculate fee: ' + failure);
// },
// );
// export async function handleFee(estimateFee, chainId: ChainId, address: Address) {
// estimateFee(chainId, (builder: ExtrinsicBuilder) =>
// builder.addCall(builder.api.tx.balances.transferKeepAlive(decodeAddress(address), '0')),
// ).then(
// (fee) => {
// alert('Fee: ' + fee);
// },
// (failure) => {
// alert('Failed to calculate fee: ' + failure);
// },
// );
// }
2 changes: 1 addition & 1 deletion src/pages/onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function OnboardingPage() {

useEffect(() => {
webApp?.CloudStorage.getItem(MNEMONIC_STORE, (_err, value) => {
setMnenonic(value);
setMnenonic(value as string | null);
});

// to avoid blinking
Expand Down
46 changes: 0 additions & 46 deletions src/screens/password/Password.tsx

This file was deleted.

0 comments on commit 1e88a94

Please sign in to comment.