Skip to content

Commit

Permalink
Merge branch 'x' into fix-input-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
huhuanming authored Oct 9, 2024
2 parents 0182906 + a01ac6b commit 34b38be
Show file tree
Hide file tree
Showing 90 changed files with 3,368 additions and 208 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@
"electron-root-path": "^1.1.0",
"electron-taskbar-badge": "1.1.2",
"eslint": "^8.25.0",
"ethersV6": "npm:ethers@^6.11.1",
"event-source-polyfill": "^1.0.31",
"expiry-map": "^2.0.0",
"expo": "50.0.20",
"jotai": "^2.5.0",
"js-md5": "^0.8.3",
"lightweight-charts": "^3.8.0",
"long": "^5.2.1",
"lru-cache": "^10.2.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/hooks/useStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export {
useTheme,
useMedia,
useThemeName,
useStyle,
usePropsAndStyle,
} from 'tamagui';

export type IThemeColorKeys = keyof UseThemeResult;
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/primitives/Icon/Icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ const icons = {
TouchId2Outline: () => import("./react/outline/TouchId2"),
TradeOutline: () => import("./react/outline/Trade"),
TranscriptionOutline: () => import("./react/outline/Transcription"),
TranslateOutline: () => import("./react/outline/Translate"),
TreeOutline: () => import("./react/outline/Tree"),
TruckOutline: () => import("./react/outline/Truck"),
UfoOutline: () => import("./react/outline/Ufo"),
Expand Down Expand Up @@ -1894,6 +1895,7 @@ const icons = {
TouchId2Solid: () => import("./react/solid/TouchId2"),
TradeSolid: () => import("./react/solid/Trade"),
TranscriptionSolid: () => import("./react/solid/Transcription"),
TranslateSolid: () => import("./react/solid/Translate"),
TreeSolid: () => import("./react/solid/Tree"),
TruckSolid: () => import("./react/solid/Truck"),
UfoSolid: () => import("./react/solid/Ufo"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Svg, { SvgProps, Path } from 'react-native-svg';
const SvgTranslate = (props: SvgProps) => (
<Svg viewBox="0 0 24 24" fill="none" accessibilityRole="image" {...props}>
<Path
fillRule="evenodd"
clipRule="evenodd"
d="M8 3a1 1 0 0 1 1 1v1h3a1 1 0 0 1 0 2h-.627c-.313 1.912-.929 3.524-1.936 4.819.751.525 1.674.928 2.806 1.21a1 1 0 0 1-.485 1.941c-1.461-.365-2.717-.928-3.758-1.725-1.04.797-2.296 1.36-3.757 1.725a1 1 0 1 1-.485-1.94c1.131-.283 2.054-.686 2.805-1.211C5.556 10.524 4.94 8.912 4.628 7H4a1 1 0 0 1 0-2h3V4a1 1 0 0 1 1-1ZM6.658 7c.266 1.414.716 2.527 1.342 3.401C8.627 9.527 9.076 8.414 9.342 7H6.658Zm8.499 4.3c.687-1.631 3-1.631 3.686 0l3.079 7.312a1 1 0 0 1-1.843.776L19.494 18h-4.988l-.584 1.388a1 1 0 0 1-1.843-.776l3.078-7.311Zm.191 4.7h3.304L17 12.077 15.348 16Z"
fill="currentColor"
/>
</Svg>
);
export default SvgTranslate;
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ export { default as TouchId } from './TouchId';
export { default as TouchId2 } from './TouchId2';
export { default as Trade } from './Trade';
export { default as Transcription } from './Transcription';
export { default as Translate } from './Translate';
export { default as Tree } from './Tree';
export { default as Truck } from './Truck';
export { default as Ufo } from './Ufo';
Expand Down
12 changes: 12 additions & 0 deletions packages/components/src/primitives/Icon/react/solid/Translate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Svg, { SvgProps, Path } from 'react-native-svg';
const SvgTranslate = (props: SvgProps) => (
<Svg viewBox="0 0 24 24" fill="none" accessibilityRole="image" {...props}>
<Path
fillRule="evenodd"
clipRule="evenodd"
d="M8 3a1 1 0 0 1 1 1v1h3a1 1 0 0 1 0 2h-.627c-.313 1.912-.929 3.524-1.936 4.819.751.525 1.674.928 2.806 1.21a1 1 0 0 1-.485 1.941c-1.461-.365-2.717-.928-3.758-1.725-1.04.797-2.296 1.36-3.757 1.725a1 1 0 1 1-.485-1.94c1.131-.283 2.054-.686 2.805-1.211C5.556 10.524 4.94 8.912 4.628 7H4a1 1 0 0 1 0-2h3V4a1 1 0 0 1 1-1ZM6.658 7c.266 1.414.716 2.527 1.342 3.401C8.627 9.527 9.076 8.414 9.342 7H6.658Zm8.499 4.3c.687-1.631 3-1.631 3.686 0l3.079 7.312a1 1 0 0 1-1.843.776L19.494 18h-4.988l-.584 1.388a1 1 0 0 1-1.843-.776l3.078-7.311Zm.191 4.7h3.304L17 12.077 15.348 16Z"
fill="currentColor"
/>
</Svg>
);
export default SvgTranslate;
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ export { default as TouchId } from './TouchId';
export { default as TouchId2 } from './TouchId2';
export { default as Trade } from './Trade';
export { default as Transcription } from './Transcription';
export { default as Translate } from './Translate';
export { default as Tree } from './Tree';
export { default as Truck } from './Truck';
export { default as Ufo } from './Ufo';
Expand Down
5 changes: 5 additions & 0 deletions packages/components/svg/outline/translate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/components/svg/solid/translate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/kit-bg/src/dbs/simple/base/SimpleDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SimpleDbEntityBrowserBookmarks } from '../entity/SimpleDbEntityBrowserB
import { SimpleDbEntityBrowserHistory } from '../entity/SimpleDbEntityBrowserHistory';
import { SimpleDbEntityBrowserRiskWhiteList } from '../entity/SimpleDbEntityBrowserRiskWhiteList';
import { SimpleDbEntityBrowserTabs } from '../entity/SimpleDbEntityBrowserTabs';
import { SimpleDbEntityCustomNetwork } from '../entity/SimpleDbEntityCustomNetwork';
import { SimpleDbEntityCustomRpc } from '../entity/SimpleDbEntityCustomRPC';
import { SimpleDbEntityCustomTokens } from '../entity/SimpleDbEntityCustomTokens';
import { SimpleDbEntityDappConnection } from '../entity/SimpleDbEntityDappConnection';
Expand Down Expand Up @@ -70,6 +71,8 @@ export class SimpleDb {

customRpc = new SimpleDbEntityCustomRpc();

customNetwork = new SimpleDbEntityCustomNetwork();

v4MigrationResult = new SimpleDbEntityV4MigrationResult();

accountValue = new SimpleDbEntityAccountValue();
Expand Down
5 changes: 5 additions & 0 deletions packages/kit-bg/src/dbs/simple/base/SimpleDbProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { SimpleDbEntityBrowserBookmarks } from '../entity/SimpleDbEntityBro
import type { SimpleDbEntityBrowserHistory } from '../entity/SimpleDbEntityBrowserHistory';
import type { SimpleDbEntityBrowserRiskWhiteList } from '../entity/SimpleDbEntityBrowserRiskWhiteList';
import type { SimpleDbEntityBrowserTabs } from '../entity/SimpleDbEntityBrowserTabs';
import type { SimpleDbEntityCustomNetwork } from '../entity/SimpleDbEntityCustomNetwork';
import type { SimpleDbEntityCustomRpc } from '../entity/SimpleDbEntityCustomRPC';
import type { SimpleDbEntityCustomTokens } from '../entity/SimpleDbEntityCustomTokens';
import type { SimpleDbEntityDappConnection } from '../entity/SimpleDbEntityDappConnection';
Expand Down Expand Up @@ -125,6 +126,10 @@ export class SimpleDbProxy

customRpc = this._createProxyService('customRpc') as SimpleDbEntityCustomRpc;

customNetwork = this._createProxyService(
'customNetwork',
) as SimpleDbEntityCustomNetwork;

v4MigrationResult = this._createProxyService(
'v4MigrationResult',
) as SimpleDbEntityV4MigrationResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { backgroundMethod } from '@onekeyhq/shared/src/background/backgroundDecorators';
import type { ENetworkStatus, IServerNetwork } from '@onekeyhq/shared/types';

import { SimpleDbEntityBase } from '../base/SimpleDbEntityBase';

export interface ICustomNetworkDBStruct {
data: Record<
string,
IServerNetwork & { createdAt: number; updatedAt: number }
>;
}

export class SimpleDbEntityCustomNetwork extends SimpleDbEntityBase<ICustomNetworkDBStruct> {
entityName = 'customNetwork';

override enableCache = false;

@backgroundMethod()
async upsertCustomNetwork(params: { networkInfo: IServerNetwork }) {
const { networkInfo } = params;
await this.setRawData(({ rawData }) => {
const data: ICustomNetworkDBStruct = {
data: { ...(rawData?.data || {}) },
};
const now = Date.now();
const existingNetwork = data.data[networkInfo.id];

data.data[networkInfo.id] = {
...networkInfo,
createdAt: existingNetwork?.createdAt || now,
updatedAt: now,
};
return data;
});
}

@backgroundMethod()
async deleteCustomNetwork(params: { networkId: string }) {
const { networkId } = params;
await this.setRawData(({ rawData }) => {
const data: ICustomNetworkDBStruct = {
data: { ...(rawData?.data || {}) },
};
delete data.data[networkId];
return data;
});
}

@backgroundMethod()
async getAllCustomNetworks(): Promise<IServerNetwork[]> {
const rawData = await this.getRawData();
return Object.values(rawData?.data || {}).sort(
(a, b) => (b?.createdAt ?? 0) - (a?.createdAt ?? 0),
);
}

@backgroundMethod()
async getCustomNetwork(params: { networkId: string }) {
const { networkId } = params;
const rawData = await this.getRawData();
return rawData?.data?.[networkId];
}

@backgroundMethod()
async updateNetworkStatus(params: {
networkId: string;
status: ENetworkStatus;
}) {
const { networkId, status } = params;
await this.setRawData(({ rawData }) => {
const data: ICustomNetworkDBStruct = {
data: { ...(rawData?.data || {}) },
};
if (data.data[networkId]) {
data.data[networkId] = {
...data.data[networkId],
status,
updatedAt: Date.now(),
};
}
return data;
});
}
}
42 changes: 42 additions & 0 deletions packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityLocalTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { keyBy, merge } from 'lodash';

import { backgroundMethod } from '@onekeyhq/shared/src/background/backgroundDecorators';
import { OneKeyInternalError } from '@onekeyhq/shared/src/errors';
import { buildFuse } from '@onekeyhq/shared/src/modules3rdParty/fuse';
import accountUtils, {
buildAccountLocalAssetsKey,
} from '@onekeyhq/shared/src/utils/accountUtils';
Expand Down Expand Up @@ -76,6 +77,47 @@ export class SimpleDbEntityLocalTokens extends SimpleDbEntityBase<ILocalTokens>
}
}

@backgroundMethod()
async getTokens({
networkId,
tokenIdOnNetworkList,
}: {
networkId: string;
tokenIdOnNetworkList: string[];
}) {
const tokenMap = (await this.getRawData())?.data;
if (!tokenMap) {
return [];
}

return tokenIdOnNetworkList
.map((tokenIdOnNetwork) => {
const tokenId = accountUtils.buildLocalTokenId({
networkId,
tokenIdOnNetwork,
});
return tokenMap[tokenId];
})
.filter((token): token is IToken => !!token);
}

@backgroundMethod()
async searchTokens(params: { keywords: string }): Promise<IToken[]> {
const rawData = await this.getRawData();
const tokenMap = rawData?.data;

if (!tokenMap) {
return [];
}

const tokens = Object.values(tokenMap);
const fuse = buildFuse(tokens, {
keys: ['address'],
});
const result = fuse.search(params.keywords).map((i) => i.item);
return result;
}

@backgroundMethod()
async updateAccountTokenList({
networkId,
Expand Down
Loading

0 comments on commit 34b38be

Please sign in to comment.