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

New storage structure #141

Merged
merged 58 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
167f364
feat: wallets state refactored
siandreev Jul 2, 2024
f499026
feat: import mnemonic wallet version & change wallet version
siandreev Jul 9, 2024
83f0e2e
chore: pro subscription minor changes
siandreev Jul 11, 2024
2b055e7
chore: merge main
siandreev Jul 11, 2024
21914f6
Merge remote-tracking branch 'origin/main' into feature/multisig
siandreev Jul 11, 2024
9ded9c0
chore: merge v5r1
siandreev Jul 11, 2024
fd3afbc
chore: eslint fixes
siandreev Jul 12, 2024
55ecd3d
Merge branch 'refs/heads/main' into feature/new-storage-structure
siandreev Jul 12, 2024
6eb90cf
fix: resolve merge conflicts
siandreev Jul 12, 2024
0412ea3
fix: added enable v5 dev flag
siandreev Jul 16, 2024
186347c
fix: rename wallet while creating or importing
siandreev Jul 16, 2024
bb1a105
feat: new accounts storage structure
siandreev Jul 24, 2024
2622546
feat: accounts maid as classes
siandreev Jul 25, 2024
15249be
feat: two-layers desktop aside
siandreev Jul 25, 2024
90af308
fix: aside & aside header improvements
siandreev Jul 26, 2024
63ed212
fix: web dropdown; ledger import improvements
siandreev Jul 26, 2024
812c9e2
fix: extension fixes
siandreev Jul 26, 2024
644cc06
Merge branch 'refs/heads/main' into feature/new-storage-structure
siandreev Jul 26, 2024
ff1d3db
fix: twa fixes
siandreev Jul 26, 2024
26c0ec1
chore: extension fixes
siandreev Jul 29, 2024
d8a1869
chore: extension build config fixes
siandreev Jul 29, 2024
0c1f657
Merge branch 'refs/heads/main' into feature/new-storage-structure
siandreev Jul 30, 2024
cc602a2
fix: update ledger blind signing for new accounts structure
siandreev Jul 30, 2024
6f14e14
fix: use created keystone name
siandreev Jul 30, 2024
266eaa1
fix: tonconnect & multisend issues
siandreev Jul 30, 2024
6716af0
fix: restructured create and import wallet components. Fix case when …
siandreev Jul 30, 2024
0cb6da1
fix: added signer versions change setting for all platforms. Style sc…
siandreev Jul 31, 2024
3fd5383
fix: update badges
siandreev Jul 31, 2024
1146004
fix: add address copied toast when copy address on click on main screen
siandreev Jul 31, 2024
db19c3e
fix: can't log out from a wallet
siandreev Jul 31, 2024
cfc0bfe
fix: add close button to the wallet name modal
siandreev Jul 31, 2024
ca0d304
fix: update web version home page badges
siandreev Jul 31, 2024
3908fb5
fix: single component for accounts badges; fix broken ton connect
siandreev Jul 31, 2024
34431d0
fix: update ton connect notification -- write full wallet and account…
siandreev Jul 31, 2024
150ac14
fix: sort signer wallets in aside menu
siandreev Jul 31, 2024
ca3dd9f
fix: fix recovery navigation
siandreev Jul 31, 2024
ef962b4
fix: fix keystone name and color
siandreev Jul 31, 2024
693e974
fix: add ios and android values to `theme.os`
siandreev Jul 31, 2024
6ae86c2
fix: pro subscription wallets select updated
siandreev Jul 31, 2024
f5271e5
fix: dashboard wallet name
siandreev Jul 31, 2024
a6d4e30
fix: remove w5 beta from wallets selection in pro subscription
siandreev Jul 31, 2024
74bae5c
fix: multisend fixes
siandreev Jul 31, 2024
15f078c
fix: sort wallet versions in header
siandreev Aug 1, 2024
c16d3c1
fix: remove wallet and derivation name and emoji
siandreev Aug 1, 2024
b3ff1e9
fix: account badge group styles
siandreev Aug 1, 2024
9b6d41d
fix: ledger subwallets page
siandreev Aug 1, 2024
f6fa9e7
fix: hide ledger settings in aside menu for legacy ledger accounts
siandreev Aug 1, 2024
5c1629c
fix: remove address update info link from the settings
siandreev Aug 1, 2024
31af02b
fix: remove noticoin page
siandreev Aug 1, 2024
18d8e33
fix: remove `disable_v5r1` tonendpoint flag dependencies
siandreev Aug 1, 2024
7e65c37
fix: account settings modals animation
siandreev Aug 1, 2024
7a9c034
fix: remove duplicated "sign out" option
siandreev Aug 1, 2024
15f9d58
fix: extension render props bug in history
siandreev Aug 2, 2024
d2aa785
fix: broken wallet version layout settings in the extension on a smal…
siandreev Aug 2, 2024
e44e5ad
fix: ledger storage naming
siandreev Aug 2, 2024
a33c7e4
fix: ledger storage naming 2
siandreev Aug 2, 2024
a1758aa
fix: ledger account breaks when first deriviation is not selected
siandreev Aug 2, 2024
0d6ea56
fix: web settings items
siandreev Aug 2, 2024
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
78 changes: 33 additions & 45 deletions apps/desktop/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { DesktopWalletSettingsRouting } from '@tonkeeper/uikit/dist/desktop-page
import { DesktopSwapPage } from '@tonkeeper/uikit/dist/desktop-pages/swap';
import { DesktopTokens } from '@tonkeeper/uikit/dist/desktop-pages/tokens/DesktopTokens';
import { AmplitudeAnalyticsContext, useTrackLocation } from '@tonkeeper/uikit/dist/hooks/amplitude';
import { AppContext, WalletStateContext } from '@tonkeeper/uikit/dist/hooks/appContext';
import { AppContext, IAppContext } from '@tonkeeper/uikit/dist/hooks/appContext';
import {
AfterImportAction,
AppSdkContext,
Expand All @@ -55,12 +55,11 @@ import { UnlockNotification } from '@tonkeeper/uikit/dist/pages/home/UnlockNotif
import ImportRouter from '@tonkeeper/uikit/dist/pages/import';
import Initialize, { InitializeContainer } from '@tonkeeper/uikit/dist/pages/import/Initialize';
import { UserThemeProvider } from '@tonkeeper/uikit/dist/providers/UserThemeProvider';
import { useAccountState } from '@tonkeeper/uikit/dist/state/account';
import { useUserFiat } from '@tonkeeper/uikit/dist/state/fiat';
import { useAuthState, useCanPromptTouchId } from '@tonkeeper/uikit/dist/state/password';
import { useCanPromptTouchId } from '@tonkeeper/uikit/dist/state/password';
import { useProBackupState } from '@tonkeeper/uikit/dist/state/pro';
import { useTonendpoint, useTonenpointConfig } from '@tonkeeper/uikit/dist/state/tonendpoint';
import { useActiveWallet } from '@tonkeeper/uikit/dist/state/wallet';
import { useActiveWalletQuery, useWalletsStateQuery } from '@tonkeeper/uikit/dist/state/wallet';
import { Container, GlobalStyleCss } from '@tonkeeper/uikit/dist/styles/globalStyle';
import { FC, Suspense, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
Expand All @@ -80,6 +79,8 @@ import { DeepLinkSubscription } from './components/DeepLink';
import { TonConnectSubscription } from './components/TonConnectSubscription';
import { DesktopDns } from '@tonkeeper/uikit/dist/desktop-pages/nft/DesktopDns';
import { DesktopCollectables } from '@tonkeeper/uikit/dist/desktop-pages/nft/DesktopCollectables';
import { useUserLanguage } from '@tonkeeper/uikit/dist/state/language';
import { useDebuggingTools } from '@tonkeeper/uikit/dist/hooks/useDebuggingTools';

const queryClient = new QueryClient({
defaultOptions: {
Expand Down Expand Up @@ -121,7 +122,6 @@ const sdk = new DesktopAppSdk();
const TARGET_ENV = 'desktop';

const langs = 'en,zh_CN,ru,it,tr';
const listOfAuth: AuthState['kind'][] = ['keychain'];

declare const REACT_APP_TONCONSOLE_API: string;
declare const REACT_APP_TG_BOT_ID: string;
Expand Down Expand Up @@ -254,47 +254,44 @@ const FullSizeWrapperBounded = styled(FullSizeWrapper)`
`;

export const Loader: FC = () => {
const { data: activeWallet } = useActiveWallet();
const { data: activeWallet, isLoading: activeWalletLoading } = useActiveWalletQuery();
const { data: wallets, isLoading: isWalletsLoading } = useWalletsStateQuery();
const { data: lang, isLoading: isLangLoading } = useUserLanguage();

const lock = useLock(sdk);
const { i18n } = useTranslation();
const { data: account } = useAccountState();
const { data: auth } = useAuthState();
const { data: fiat } = useUserFiat();

const tonendpoint = useTonendpoint({
targetEnv: TARGET_ENV,
build: sdk.version,
network: activeWallet?.network,
lang: activeWallet?.lang,
lang,
platform: 'desktop'
});
const { data: config } = useTonenpointConfig(tonendpoint);

const navigate = useNavigate();
useAppHeight();

const { data: tracker } = useAnalytics(sdk.version, account, activeWallet);
const { data: tracker } = useAnalytics(sdk.version, activeWallet, wallets);

useEffect(() => {
if (
activeWallet &&
activeWallet.lang &&
i18n.language !== localizationText(activeWallet.lang)
) {
i18n.reloadResources([localizationText(activeWallet.lang)]).then(() =>
i18n.changeLanguage(localizationText(activeWallet.lang))
if (lang && i18n.language !== localizationText(lang)) {
i18n.reloadResources([localizationText(lang)]).then(() =>
i18n.changeLanguage(localizationText(lang))
);
}
}, [activeWallet, i18n]);
}, [lang, i18n]);

useEffect(() => {
window.backgroundApi.onRefresh(() => queryClient.invalidateQueries());
}, []);

if (
auth === undefined ||
account === undefined ||
activeWalletLoading ||
isLangLoading ||
isWalletsLoading ||
config === undefined ||
lock === undefined ||
fiat === undefined
Expand All @@ -303,11 +300,9 @@ export const Loader: FC = () => {
}

const network = activeWallet?.network ?? Network.MAINNET;
const context = {
const context: IAppContext = {
api: getApiConfig(config, network, REACT_APP_TONCONSOLE_API),
auth,
fiat,
account,
config,
tonendpoint,
standalone: true,
Expand Down Expand Up @@ -352,6 +347,7 @@ export const Content: FC<{
useAppWidth();
useTrackLocation();
usePrefetch();
useDebuggingTools();

if (lock) {
return (
Expand All @@ -366,10 +362,7 @@ export const Content: FC<{
<FullSizeWrapperBounded className="full-size-wrapper">
<InitializeContainer fullHeight={false}>
<Routes>
<Route
path={any(AppRoute.import)}
element={<ImportRouter listOfAuth={listOfAuth} />}
/>
<Route path={any(AppRoute.import)} element={<ImportRouter />} />
<Route path="*" element={<Initialize />} />
</Routes>
</InitializeContainer>
Expand All @@ -378,24 +371,19 @@ export const Content: FC<{
}

return (
<WalletStateContext.Provider value={activeWallet}>
<WideLayout>
<AsideMenu />
<WideContent>
<Routes>
<Route path={AppProRoute.dashboard} element={<DashboardPage />} />
<Route path={AppRoute.browser} element={<DesktopBrowser />} />
<Route path={any(AppRoute.settings)} element={<PreferencesContent />} />
<Route
path={any(AppProRoute.multiSend)}
element={<DesktopMultiSendPage />}
/>
<Route path="*" element={<WalletContent />} />
</Routes>
</WideContent>
<BackgroundElements />
</WideLayout>
</WalletStateContext.Provider>
<WideLayout>
<AsideMenu />
<WideContent>
<Routes>
<Route path={AppProRoute.dashboard} element={<DashboardPage />} />
<Route path={AppRoute.browser} element={<DesktopBrowser />} />
<Route path={any(AppRoute.settings)} element={<PreferencesContent />} />
<Route path={any(AppProRoute.multiSend)} element={<DesktopMultiSendPage />} />
<Route path="*" element={<WalletContent />} />
</Routes>
</WideContent>
<BackgroundElements />
</WideLayout>
);
};

Expand Down
32 changes: 20 additions & 12 deletions apps/desktop/src/electron/sseEvetns.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TonConnectAppRequest } from '@tonkeeper/core/dist/entries/tonConnect';
import { accountSelectWallet, getAccountState } from '@tonkeeper/core/dist/service/accountService';
import {
replyBadRequestResponse,
replyDisconnectResponse
Expand All @@ -13,20 +12,21 @@ import {
getLastEventId,
subscribeTonConnect
} from '@tonkeeper/core/dist/service/tonConnect/httpBridge';
import { getWalletState } from '@tonkeeper/core/dist/service/wallet/storeService';
import { walletsStorage } from '@tonkeeper/core/dist/service/walletsService';
import { delay } from '@tonkeeper/core/dist/utils/common';
import { Buffer as BufferPolyfill } from 'buffer';
import log from 'electron-log/main';
import EventSourcePolyfill from 'eventsource';
import { MainWindow } from './mainWindow';
import { mainStorage } from './storageService';
import { isStandardTonWallet, WalletId } from '@tonkeeper/core/dist/entries/wallet';

globalThis.Buffer = BufferPolyfill;

export class TonConnectSSE {
private lastEventId: string;
private connections: AccountConnection[];
private dist: Record<string, string>;
private dist: Record<string, WalletId>;
private closeConnection: () => void | null = null;

private static instance: TonConnectSSE = null;
Expand All @@ -48,18 +48,19 @@ export class TonConnectSSE {
public async init() {
this.lastEventId = await getLastEventId(mainStorage);

const account = await getAccountState(mainStorage);
const walletsState = (await walletsStorage(mainStorage).getWallets()).filter(
isStandardTonWallet
);

this.connections = [];
this.dist = {};

for (const key of account.publicKeys) {
const wallet = await getWalletState(mainStorage, key);
for (const wallet of walletsState) {
const walletConnections = await getAccountConnection(mainStorage, wallet);

this.connections = this.connections.concat(walletConnections);
walletConnections.forEach(item => {
this.dist[item.clientSessionId] = key;
this.dist[item.clientSessionId] = wallet.id;
});
}
}
Expand All @@ -78,7 +79,14 @@ export class TonConnectSSE {
};

private onDisconnect = async ({ connection, request }: TonConnectAppRequest) => {
const wallet = await getWalletState(mainStorage, this.dist[connection.clientSessionId]);
const wallet = await walletsStorage(mainStorage).getWallet(
this.dist[connection.clientSessionId]
);

if (!wallet || !isStandardTonWallet(wallet)) {
return;
}

await disconnectAppConnection({
storage: mainStorage,
wallet,
Expand All @@ -101,14 +109,14 @@ export class TonConnectSSE {
payload: JSON.parse(params.request.params[0])
};

const walletPublicKey = this.dist[params.connection.clientSessionId];
const walletId = this.dist[params.connection.clientSessionId];

const account = await getAccountState(mainStorage);
const activeWalletId = await walletsStorage(mainStorage).getActiveWalletId();

const window = await MainWindow.bringToFront();

if (account.activePublicKey !== walletPublicKey) {
await accountSelectWallet(mainStorage, walletPublicKey);
if (activeWalletId !== walletId) {
await walletsStorage(mainStorage).setActiveWalletId(walletId);
window.webContents.send('refresh');
await delay(500);
}
Expand Down
9 changes: 5 additions & 4 deletions apps/desktop/src/libs/aptabaseElectron.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import { trackEvent } from '@aptabase/electron/renderer';
import { Network } from '@tonkeeper/core/dist/entries/network';
import { Analytics } from '@tonkeeper/uikit/dist/hooks/analytics';
import { WalletsState, WalletState } from '@tonkeeper/core/dist/entries/wallet';

export class AptabaseElectron implements Analytics {
private user_properties: Record<string, any> = {};

init = (
application: string,
walletType: string,
account?: any,
wallet?: any,
activeWallet?: WalletState,
wallets?: WalletsState,
version?: string | undefined,
platform?: string | undefined
) => {
this.user_properties['application'] = application;
this.user_properties['walletType'] = walletType;
this.user_properties['network'] =
wallet?.network === Network.TESTNET ? 'testnet' : 'mainnet';
this.user_properties['accounts'] = account!.publicKeys.length;
activeWallet?.network === Network.TESTNET ? 'testnet' : 'mainnet';
this.user_properties['accounts'] = wallets?.length ?? 0;
this.user_properties['version'] = version;
this.user_properties['platform'] = platform;
};
Expand Down
15 changes: 7 additions & 8 deletions apps/desktop/src/libs/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useQuery } from '@tanstack/react-query';
import { AppKey } from '@tonkeeper/core/dist/Keys';
import { AccountState } from '@tonkeeper/core/dist/entries/account';
import { WalletState } from '@tonkeeper/core/dist/entries/wallet';
import { WalletsState, WalletState } from '@tonkeeper/core/dist/entries/wallet';
import { throttle } from '@tonkeeper/core/dist/utils/common';
import { Analytics, AnalyticsGroup, toWalletType } from '@tonkeeper/uikit/dist/hooks/analytics';
import { Amplitude } from '@tonkeeper/uikit/dist/hooks/analytics/amplitude';
Expand Down Expand Up @@ -50,8 +49,8 @@ declare const REACT_APP_AMPLITUDE: string;

export const useAnalytics = (
version: string,
account?: AccountState,
wallet?: WalletState | null
activeWallet?: WalletState,
wallets?: WalletsState
) => {
const sdk = useAppSdk();

Expand All @@ -77,15 +76,15 @@ export const useAnalytics = (

tracker.init(
'Desktop',
toWalletType(wallet),
account,
wallet,
toWalletType(activeWallet),
activeWallet,
wallets,
version,
`${window.backgroundApi.platform()}-${window.backgroundApi.arch()}`
);

return tracker;
},
{ enabled: account != null }
{ enabled: wallets != null && activeWallet !== undefined }
);
};
Loading
Loading