Skip to content

Commit

Permalink
feat: support dragging the floating icon. (#6436)
Browse files Browse the repository at this point in the history
  • Loading branch information
huhuanming authored Jan 7, 2025
1 parent c8027cc commit e9114ce
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/kit-bg/src/apis/backgroundApiPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const PROVIDER_API_PRIVATE_WHITE_LIST_METHOD = [
'wallet_sendSiteMetadata',
'wallet_scanQrcode',
'wallet_isShowFloatingButton',
'wallet_saveFloatingIconSettings',
'wallet_disableFloatingButton',
'wallet_hideFloatingButtonOnSite',
'wallet_detectRiskLevel',
Expand Down
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 @@ -18,6 +18,7 @@ import { SimpleDbEntityEarn } from '../entity/SimpleDbEntityEarn';
import { SimpleDbEntityEarnOrders } from '../entity/SimpleDbEntityEarnOrders';
import { SimpleDbEntityFeeInfo } from '../entity/SimpleDbEntityFeeInfo';
import { SimpleDbEntityFloatingIconDomainBlockList } from '../entity/SimpleDbEntityFloatingIconDomainBlockList';
import { SimpleDbEntityFloatingIconSettings } from '../entity/SimpleDbEntityFloatingIconSettings';
import { SimpleDbEntityLegacyWalletNames } from '../entity/SimpleDbEntityLegacyWalletNames';
import { SimpleDbEntityLightning } from '../entity/SimpleDbEntityLightning';
import { SimpleDbEntityLocalHistory } from '../entity/SimpleDbEntityLocalHistory';
Expand Down Expand Up @@ -79,6 +80,8 @@ export class SimpleDb {

floatingIconDomainBlockList = new SimpleDbEntityFloatingIconDomainBlockList();

floatingIconSettings = new SimpleDbEntityFloatingIconSettings();

earn = new SimpleDbEntityEarn();

earnOrders = new SimpleDbEntityEarnOrders();
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 @@ -22,6 +22,7 @@ import type { SimpleDbEntityEarn } from '../entity/SimpleDbEntityEarn';
import type { SimpleDbEntityEarnOrders } from '../entity/SimpleDbEntityEarnOrders';
import type { SimpleDbEntityFeeInfo } from '../entity/SimpleDbEntityFeeInfo';
import type { SimpleDbEntityFloatingIconDomainBlockList } from '../entity/SimpleDbEntityFloatingIconDomainBlockList';
import type { SimpleDbEntityFloatingIconSettings } from '../entity/SimpleDbEntityFloatingIconSettings';
import type { SimpleDbEntityLegacyWalletNames } from '../entity/SimpleDbEntityLegacyWalletNames';
import type { SimpleDbEntityLightning } from '../entity/SimpleDbEntityLightning';
import type { SimpleDbEntityLocalHistory } from '../entity/SimpleDbEntityLocalHistory';
Expand Down Expand Up @@ -140,6 +141,10 @@ export class SimpleDbProxy
'floatingIconDomainBlockList',
) as SimpleDbEntityFloatingIconDomainBlockList;

floatingIconSettings = this._createProxyService(
'floatingIconSettings',
) as SimpleDbEntityFloatingIconSettings;

universalSearch = this._createProxyService(
'universalSearch',
) as SimpleDbEntityUniversalSearch;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { backgroundMethod } from '@onekeyhq/shared/src/background/backgroundDecorators';

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

export interface IFloatingIconSettings {
position: {
side: 'left' | 'right';
bottom: string;
};
}

const DEFAULT_POSITION: IFloatingIconSettings['position'] = {
side: 'right',
bottom: '30%',
};

export class SimpleDbEntityFloatingIconSettings extends SimpleDbEntityBase<IFloatingIconSettings> {
entityName = 'floatingIconSettings';

override enableCache = false;

@backgroundMethod()
async getSettings(): Promise<IFloatingIconSettings> {
const result =
(await this.getRawData()) || ({} as Partial<IFloatingIconSettings>);
const position = result.position || DEFAULT_POSITION;
return {
position,
};
}

@backgroundMethod()
async setSettings(settings: Partial<IFloatingIconSettings> | undefined) {
if (!settings) {
return;
}
const dbSettings = await this.getSettings();
const position = settings.position || dbSettings.position;
await this.setRawData({
position: {
side: position.side || DEFAULT_POSITION.side,
bottom: position.bottom || DEFAULT_POSITION.bottom,
},
});
}
}
13 changes: 13 additions & 0 deletions packages/kit-bg/src/providers/ProviderApiPrivate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import ProviderApiBase from './ProviderApiBase';
import type { IProviderBaseBackgroundNotifyInfo } from './ProviderApiBase';
import type BackgroundApiBase from '../apis/BackgroundApiBase';
import type { IBackgroundApiWebembedCallMessage } from '../apis/IBackgroundApi';
import type { IFloatingIconSettings } from '../dbs/simple/entity/SimpleDbEntityFloatingIconSettings';
import type { IJsBridgeMessagePayload } from '@onekeyfe/cross-inpage-provider-types';

export interface IOneKeyWalletInfo {
Expand Down Expand Up @@ -290,8 +291,11 @@ class ProviderApiPrivate extends ProviderApiBase {
await this.backgroundApi.serviceSetting.shouldDisplayFloatingButtonInUrl(
{ url: request.origin },
);
const settings =
await this.backgroundApi.simpleDb.floatingIconSettings.getSettings();
return {
isShow,
settings,
i18n: {
title: appLocale.intl.formatMessage({
id: ETranslations.explore_malicious_dapp,
Expand Down Expand Up @@ -356,6 +360,15 @@ class ProviderApiPrivate extends ProviderApiBase {
};
}

@providerApiMethod()
async wallet_saveFloatingIconSettings(request: IJsBridgeMessagePayload) {
console.log('ProviderApiPrivate.wallet_saveFloatingIconSettings', request);
const { params } = request.data as {
params?: Partial<IFloatingIconSettings>;
};
await this.backgroundApi.simpleDb.floatingIconSettings.setSettings(params);
}

/*
window.$onekey.$private.request({
method: 'wallet_disableFloatingButton',
Expand Down

0 comments on commit e9114ce

Please sign in to comment.