Skip to content

Commit

Permalink
Merge branch 'develop' into feat/custom-testnet-1
Browse files Browse the repository at this point in the history
  • Loading branch information
cs1707 committed Dec 4, 2024
2 parents ab1488b + 90eb11f commit 51324ba
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 11 deletions.
2 changes: 1 addition & 1 deletion _raw/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@
"title": "Welcome to Rabby Wallet",
"desc": "The game-changing wallet for Ethereum and all EVM chains",
"createNewAddress": "Create a new address",
"importAddress": "I already have a address"
"importAddress": "I already have an address"
},
"createNewAddress": {
"title": "Create New Seed Phrase",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rabby",
"version": "0.93.1",
"version": "0.93.2",
"description": "A browser plugin for DeFi users",
"scripts": {
"clean": "mkdir -p dist && rm -rf dist/*",
Expand Down Expand Up @@ -56,7 +56,7 @@
"@rabby-wallet/eth-lattice-keyring": "1.2.1",
"@rabby-wallet/eth-simple-keyring": "5.0.1",
"@rabby-wallet/eth-trezor-keyring": "2.6.1",
"@rabby-wallet/eth-walletconnect-keyring": "2.1.3",
"@rabby-wallet/eth-walletconnect-keyring": "2.1.5",
"@rabby-wallet/eth-watch-keyring": "1.0.0",
"@rabby-wallet/gnosis-sdk": "1.3.9",
"@rabby-wallet/page-provider": "0.4.2",
Expand Down
13 changes: 12 additions & 1 deletion src/background/controller/provider/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
KEYRING_CATEGORY_MAP,
EVENTS,
INTERNAL_REQUEST_SESSION,
INTERNAL_REQUEST_ORIGIN,
} from 'consts';
import buildinProvider from 'background/utils/buildinProvider';
import BaseController from '../base';
Expand Down Expand Up @@ -165,9 +166,11 @@ class ProviderController extends BaseController {
ethRpc = (req, forceChainServerId?: string) => {
const {
data: { method, params },
session: { origin },
session: { origin: _origin },
} = req;

let origin = _origin;

if (
!permissionService.hasPermission(origin) &&
!SAFE_RPC_METHODS.includes(method)
Expand All @@ -176,6 +179,14 @@ class ProviderController extends BaseController {
}

const site = permissionService.getSite(origin);

if (method === 'net_version') {
if (!site?.isConnected) {
return Promise.resolve('1');
}
origin = INTERNAL_REQUEST_ORIGIN;
}

let chainServerId = CHAINS[CHAINS_ENUM.ETH].serverId;
if (site) {
chainServerId =
Expand Down
5 changes: 5 additions & 0 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
HDKeyRingLastAddAddrTimeService,
bridgeService,
gasAccountService,
uninstalledService,
} from 'background/service';
import buildinProvider, {
EthereumProvider,
Expand Down Expand Up @@ -1493,6 +1494,8 @@ export class WalletController extends BaseController {
} else {
setPopupIcon(isDefaultWallet ? 'rabby' : 'metamask');
}

uninstalledService.syncStatus();
};
isUnlocked = () => keyringService.isUnlocked();

Expand Down Expand Up @@ -4908,6 +4911,8 @@ export class WalletController extends BaseController {
await userGuideService.activeUserGuide();
return true;
};

uninstalledSyncStatus = uninstalledService.syncStatus;
}

const wallet = new WalletController();
Expand Down
4 changes: 4 additions & 0 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
HDKeyRingLastAddAddrTimeService,
bridgeService,
gasAccountService,
uninstalledService,
} from './service';
import { providerController, walletController } from './controller';
import { getOriginFromUrl } from '@/utils';
Expand Down Expand Up @@ -105,6 +106,7 @@ async function restoreAppState() {
await HDKeyRingLastAddAddrTimeService.init();
await bridgeService.init();
await gasAccountService.init();
await uninstalledService.init();

await walletController.tryUnlock();

Expand Down Expand Up @@ -145,6 +147,8 @@ async function restoreAppState() {
});
}
});

uninstalledService.setUninstalled();
}

restoreAppState();
Expand Down
1 change: 1 addition & 0 deletions src/background/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export { default as RabbyPointsService } from './rabbyPoints';
export { default as HDKeyRingLastAddAddrTimeService } from './HDKeyRingLastAddAddrTime';
export { default as bridgeService } from './bridge';
export { default as gasAccountService } from './gasAccount';
export { default as uninstalledService } from './uninstalled';
5 changes: 5 additions & 0 deletions src/background/service/keyring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
passwordDecrypt,
passwordClearKey,
} from 'background/utils/password';
import uninstalledMetricService from '../uninstalled';

export const KEYRING_SDK_TYPES = {
SimpleKeyring,
Expand Down Expand Up @@ -175,6 +176,9 @@ export class KeyringService extends EventEmitter {
name: alias,
});
}
uninstalledMetricService.setWalletByKeyringType(
KEYRING_TYPE.SimpleKeyring
);
return this.persistAllKeyrings.bind(this);
})
.then(this.setUnlocked.bind(this))
Expand Down Expand Up @@ -483,6 +487,7 @@ export class KeyringService extends EventEmitter {
return selectedKeyring
.addAccounts(1)
.then(() => {
uninstalledMetricService.setWalletByKeyringType(selectedKeyring.type);
if (selectedKeyring.getAccountsWithBrand) {
return selectedKeyring.getAccountsWithBrand();
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/background/service/transactionHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ActionRequireData,
ParsedTransactionActionData,
} from '@rabby-wallet/rabby-action';
import { uninstalledService } from '.';

export interface TransactionHistoryItem {
rawTx: Tx;
Expand Down Expand Up @@ -91,6 +92,8 @@ class TxHistory {
private _txHistoryLimit = 100;

addSigningTx(tx: Tx) {
uninstalledService.setTx();

const id = nanoid();

this._signingTxList.push({
Expand Down
120 changes: 120 additions & 0 deletions src/background/service/uninstalled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { createPersistStore } from 'background/utils';
import { keyringService, transactionHistoryService } from '.';
import { KEYRING_CLASS } from '@/constant';
import browser from 'webextension-polyfill';

export type UninstalledStore = {
imported: boolean;
tx?: boolean;
wallet?: boolean;
local?: boolean;
};

class Uninstalled {
store: UninstalledStore = {
imported: false,
tx: false,
wallet: false,
local: false,
};

init = async () => {
const storage = await createPersistStore<UninstalledStore>({
name: 'UninstalledMetric',
template: {
imported: false,
tx: false,
wallet: false,
local: false,
},
});

this.store = storage || this.store;
};

syncStatus = async () => {
if (
!this.store.tx &&
transactionHistoryService.store.transactions &&
Object.keys(transactionHistoryService.store.transactions).length
) {
this.setTx();
this.setImported();
}

if (this.store.wallet) {
return;
}

const typedAccounts = await keyringService.getAllTypedAccounts();
if (typedAccounts.length) {
typedAccounts.forEach((account) => {
this.setWalletByKeyringType(account.type);
});
}
};

setImported = () => {
this.store.imported = true;
this.setUninstalled();
};

setWallet = () => {
this.store.wallet = true;
this.setUninstalled();
};

setTx = () => {
this.store.tx = true;
this.setUninstalled();
};

setLocal = () => {
this.store.local = true;
this.setUninstalled();
};

setWalletByKeyringType = (keyringType: string) => {
if (this.store.imported && this.store.wallet && this.store.local) {
return;
}
this.setImported();
let isLocal = false;
let isHardware = false;
isLocal = ([
KEYRING_CLASS.PRIVATE_KEY,
KEYRING_CLASS.MNEMONIC,
] as string[]).includes(keyringType);
isHardware = ([
...Object.values(KEYRING_CLASS.HARDWARE),
] as string[]).includes(keyringType);
if (isLocal) {
this.setLocal();
}
if (isLocal || isHardware) {
this.setWallet();
}
};

setUninstalled = () => {
let search = '';
if (this.store.imported) {
search = 'i';
}
if (this.store.wallet) {
search += 'w';
}

if (this.store.tx) {
search += 't';
}
if (this.store.local) {
search += 'l';
}
browser.runtime.setUninstallURL(
`https://rabby.io/uninstalled?r=${encodeURIComponent(search)}`
);
};
}

export default new Uninstalled();
2 changes: 1 addition & 1 deletion src/manifest/mv2/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_appName__",
"short_name": "__MSG_appName__",
"version": "0.93.1",
"version": "0.93.2",
"default_locale": "en",
"description": "__MSG_appDescription__",
"icons": {
Expand Down
2 changes: 1 addition & 1 deletion src/manifest/mv3/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "__MSG_appName__",
"short_name": "__MSG_appName__",
"version": "0.93.1",
"version": "0.93.2",
"default_locale": "en",
"description": "__MSG_appDescription__",
"icons": {
Expand Down
7 changes: 6 additions & 1 deletion src/ui/views/NewUserImport/Success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const AccountItem = ({ account }: { account: Account }) => {

const [defaultName, setDefaultName] = useState(name || '');

const wallet = useWallet();

const updateRef = useRef(null);

const update = React.useCallback(() => {
Expand All @@ -42,7 +44,6 @@ const AccountItem = ({ account }: { account: Account }) => {
}, [updateAlias, localName, defaultName]);

useClickAway(updateRef, () => {
console.log('edit', edit);
if (edit) {
update();
}
Expand All @@ -54,6 +55,10 @@ const AccountItem = ({ account }: { account: Account }) => {
}
}, [edit]);

useEffect(() => {
wallet.uninstalledSyncStatus();
}, []);

if (!account) {
return null;
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4687,10 +4687,10 @@
ethereumjs-util "^7.1.5"
hdkey "0.8.0"

"@rabby-wallet/[email protected].3":
version "2.1.3"
resolved "https://registry.yarnpkg.com/@rabby-wallet/eth-walletconnect-keyring/-/eth-walletconnect-keyring-2.1.3.tgz#8ea63178e2fa4c9369ba2ea1df6940d016d32c2a"
integrity sha512-Yvx1uCC/E8Zv53vx0ZjHpXL+udZLgLfnER37O04i6pN2aRFmh9SFPh9nnNn7+Nh/i/Q2gz4UziCu6AjIdq5I1w==
"@rabby-wallet/[email protected].5":
version "2.1.5"
resolved "https://registry.yarnpkg.com/@rabby-wallet/eth-walletconnect-keyring/-/eth-walletconnect-keyring-2.1.5.tgz#f8a3e6c8c20bc0106583ac501c29fef19c4f2d3d"
integrity sha512-eYvr46YOnuzApgjssdyk7HzG3YXBFBit9eju9QIvE+WmZ0e1oov3/uqqQVNhCVu3WqpSBQ70bma/2tjiFPae9A==
dependencies:
"@ethereumjs/tx" "^3.5.2"
"@rabby-wallet/wc-client" "^1.8.10"
Expand Down

0 comments on commit 51324ba

Please sign in to comment.