Skip to content

Commit

Permalink
feat: safe address support mantle, world chain, blast and sonic (#2692)
Browse files Browse the repository at this point in the history
* feat: safe address support mantle, world chain, blast and sonic

* fix: safe handleConfirm

* fix: import order

---------

Co-authored-by: vvvvvv1vvvvvv <[email protected]>
  • Loading branch information
cs1707 and vvvvvv1vvvvvv authored Dec 20, 2024
1 parent 022a5db commit c0a2fc5
Show file tree
Hide file tree
Showing 19 changed files with 134 additions and 93 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@rabby-wallet/eth-trezor-keyring": "2.6.1",
"@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/gnosis-sdk": "1.3.10",
"@rabby-wallet/page-provider": "0.4.2",
"@rabby-wallet/rabby-action": "0.1.8",
"@rabby-wallet/rabby-api": "0.9.2",
Expand All @@ -69,9 +69,8 @@
"@rabby-wallet/widgets": "1.0.9",
"@rematch/core": "2.2.0",
"@rematch/select": "3.1.2",
"@safe-global/api-kit": "2.5.3",
"@safe-global/protocol-kit": "5.0.3",
"@safe-global/types-kit": "1.0.0",
"@safe-global/sdk-starter-kit": "1.1.1",
"@scure/bip39": "1.2.1",
"@sentry/browser": "6.7.2",
"@sentry/react": "6.7.2",
Expand Down
9 changes: 3 additions & 6 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ import Safe from '@rabby-wallet/gnosis-sdk';
import { Chain } from '@debank/common';
import { isAddress } from 'web3-utils';
import {
ensureChainListValid,
findChain,
findChainByEnum,
findChainByServerID,
Expand Down Expand Up @@ -130,10 +131,8 @@ import { getRecommendGas, getRecommendNonce } from './walletUtils/sign';
import { waitSignComponentAmounted } from '@/utils/signEvent';
import pRetry from 'p-retry';
import Browser from 'webextension-polyfill';
import SafeApiKit from '@safe-global/api-kit';
import { hashSafeMessage } from '@safe-global/protocol-kit';
import { userGuideService } from '../service/userGuide';
import { sleep } from '@/ui/views/HDManager/utils';

const stashKeyrings: Record<string | number, any> = {};

Expand Down Expand Up @@ -1994,7 +1993,7 @@ export class WalletController extends BaseController {
return Promise.reject(new Error(t('background.error.invalidAddress')));
}
return Promise.all(
GNOSIS_SUPPORT_CHAINS.map(async (chainEnum) => {
ensureChainListValid(GNOSIS_SUPPORT_CHAINS).map(async (chainEnum) => {
const chain = findChain({ enum: chainEnum });
try {
const safe = await createSafeService({
Expand Down Expand Up @@ -2490,9 +2489,7 @@ export class WalletController extends BaseController {
chainId: number;
messageHash: string;
}) => {
const apiKit = new SafeApiKit({
chainId: BigInt(chainId),
});
const apiKit = Safe.createSafeApiKit(String(chainId));
return apiKit.getMessage(messageHash);
};

Expand Down
10 changes: 2 additions & 8 deletions src/background/service/keyring/eth-gnosis-keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import {
import semverSatisfies from 'semver/functions/satisfies';
import EthSignSignature from '@gnosis.pm/safe-core-sdk/dist/src/utils/signatures/SafeSignature';
import SafeMessage from '@safe-global/protocol-kit/dist/src/utils/messages/SafeMessage';
import { EIP712TypedData } from '@safe-global/types-kit';
import SafeApiKit, {
EIP712TypedData as EIP712TypedDataNew,
} from '@safe-global/api-kit';
import {
adjustVInSignature,
buildSignatureBytes,
Expand Down Expand Up @@ -602,7 +598,7 @@ class GnosisKeyring extends EventEmitter {
provider: any;
version: string;
networkId: string;
message: string | EIP712TypedData;
message: ConstructorParameters<typeof SafeMessage>[0];
}) {
if (
!this.accounts.find(
Expand Down Expand Up @@ -689,9 +685,7 @@ class GnosisKeyring extends EventEmitter {
) {
throw new Error('No message in Gnosis keyring');
}
const apiKit = new SafeApiKit({
chainId: BigInt(this.safeInstance.network),
});
const apiKit = Safe.createSafeApiKit(this.safeInstance.network);
signature = await adjustVInSignature(
SigningMethod.ETH_SIGN_TYPED_DATA,
signature
Expand Down
8 changes: 6 additions & 2 deletions src/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ export const BRAND_ALIAN_TYPE_TEXT = {
[KEYRING_CLASS.HARDWARE.IMKEY]: 'imKey',
};

export const GNOSIS_SUPPORT_CHAINS = ensureChainListValid([
export const GNOSIS_SUPPORT_CHAINS = [
CHAINS_ENUM.ETH,
CHAINS_ENUM.BSC,
CHAINS_ENUM.POLYGON,
Expand All @@ -1393,7 +1393,11 @@ export const GNOSIS_SUPPORT_CHAINS = ensureChainListValid([
CHAINS_ENUM.SCRL,
CHAINS_ENUM.LINEA,
'XLAYER',
]);
CHAINS_ENUM.MANTLE,
'WORLD',
CHAINS_ENUM.BLAST,
'SONIC',
];

export const COBO_ARGUS_SUPPORT_CHAINS = ensureChainListValid([
CHAINS_ENUM.ETH,
Expand Down
3 changes: 1 addition & 2 deletions src/ui/hooks/useGnosisPendingCount.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { SafeMessage } from '@safe-global/api-kit';
import { useRequest } from 'ahooks';
import type { Options } from 'ahooks/lib/useRequest/src/types';
import { useWallet } from '../utils';
import { sum } from 'lodash';
import { useWallet } from '../utils';

export const useGnosisPendingCount = (
params: { address?: string },
Expand Down
14 changes: 4 additions & 10 deletions src/ui/hooks/useGnosisPendingMessages.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { SafeMessage } from '@safe-global/api-kit';
import { useRequest } from 'ahooks';
import type { Options } from 'ahooks/lib/useRequest/src/types';
import { useWallet } from '../utils';

export const useGnosisPendingMessages = (
params: { address?: string },
options?: Options<
| {
total: number;
results: {
networkId: string;
messages: SafeMessage[];
}[];
}
| undefined
| null,
Awaited<
ReturnType<ReturnType<typeof useWallet>['getGnosisAllPendingMessages']>
>,
any[]
>
) => {
Expand All @@ -25,6 +18,7 @@ export const useGnosisPendingMessages = (
if (address) {
return wallet.getGnosisAllPendingMessages(address);
}
return null;
},
{
refreshDeps: [address],
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/AddressDetail/GnosisSafeInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const GnonisSafeInfo = ({
<>
<div className="rabby-list-item no-hover">
<div className="rabby-list-item-content border-0">
<div className="rabby-list-item-label">
<div>
{t('page.addressDetail.admins')}
<div className="tabs-container">
<div className="tabs">
Expand Down
4 changes: 2 additions & 2 deletions src/ui/views/AddressDetail/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

.tabs {
display: flex;
gap: 16px 10px;
gap: 8px 10px;
flex-wrap: wrap;
padding-bottom: 8px;

Expand Down Expand Up @@ -127,7 +127,7 @@
font-weight: 400;
font-size: 14px;
line-height: 20px;
color: var(--r-neutral-body, #D3D8E0);
color: var(--r-neutral-body, #d3d8e0);
margin-bottom: 20px;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BasicSafeInfo } from '@rabby-wallet/gnosis-sdk';
import { SafeMessage } from '@safe-global/api-kit';
import { BasicSafeInfo, SafeMessage } from '@rabby-wallet/gnosis-sdk';
import { Button } from 'antd';
import { Account } from 'background/service/preference';
import clsx from 'clsx';
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/Approval/hooks/useCheckCurrentSafeMessage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { KEYRING_TYPE } from '@/constant';
import { useWallet } from '@/ui/utils';
import { SafeMessage } from '@safe-global/api-kit';
import { SafeMessage } from '@rabby-wallet/gnosis-sdk';
import { useRequest } from 'ahooks';
import type { Options } from 'ahooks/lib/useRequest/src/types';
import { useTranslation } from 'react-i18next';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useWallet } from '@/ui/utils';
import { getActionTypeText as getActionTypedDataTypeText } from '@/ui/views/Approval/components/TypedDataActions/utils';
import { getActionTypeText } from '@/ui/views/Approval/components/TextActions/utils';
import { parseAction } from '@rabby-wallet/rabby-action';
import { SafeMessage } from '@safe-global/api-kit';
import { SafeMessage } from '@rabby-wallet/gnosis-sdk';
import { useRequest } from 'ahooks';
import { Button, Skeleton } from 'antd';
import { isString } from 'lodash';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import clsx from 'clsx';
import React, { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';

import { SafeMessage } from '@safe-global/api-kit';
import { SafeMessage } from '@rabby-wallet/gnosis-sdk';
import IconChecked from 'ui/assets/checked.svg';
import IconTagYou from 'ui/assets/tag-you.svg';
import IconUnCheck from 'ui/assets/uncheck.svg';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, { useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import { findChain } from '@/utils/chain';
import { SafeMessage } from '@safe-global/api-kit';
import { SafeMessage } from '@rabby-wallet/gnosis-sdk';
import { useRequest } from 'ahooks';
import { timeago, useWallet } from 'ui/utils';
import { stringToHex } from 'viem';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useAccount } from '@/ui/store-hooks';
import { findChain } from '@/utils/chain';
import { LoadingOutlined } from '@ant-design/icons';
import { SafeTransactionDataPartial } from '@gnosis.pm/safe-core-sdk-types';
import { SafeMessage } from '@safe-global/api-kit';
import { SafeMessage } from '@rabby-wallet/gnosis-sdk';
import { CHAINS_ENUM } from 'consts';
import { Virtuoso } from 'react-virtuoso';
import { isSameAddress, useWallet } from 'ui/utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useGnosisNetworks } from '@/ui/hooks/useGnosisNetworks';
import { useGnosisPendingMessages } from '@/ui/hooks/useGnosisPendingMessages';
import { useAccount } from '@/ui/store-hooks';
import { findChain, findChainByEnum } from '@/utils/chain';
import { SafeMessage } from '@safe-global/api-kit';
import { SafeMessage } from '@rabby-wallet/gnosis-sdk';
import clsx from 'clsx';
import { CHAINS_ENUM } from 'consts';
import { sortBy } from 'lodash';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ export const GnosisTransactionQueueList = (props: {
);
await wallet.execGnosisTransaction(account);
setIsSubmitting(false);
window.close();
} catch (e) {
message.error(e.message || JSON.stringify(e));
setIsSubmitting(false);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/GnosisQueue/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

.tabs {
display: flex;
gap: 20px 10px;
gap: 10px 10px;
flex-wrap: wrap;
&-container {
background-color: var(--r-neutral-bg-2, #f5f6fa);
Expand Down
10 changes: 5 additions & 5 deletions src/ui/views/NewUserImport/ImportList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ export const ImportWalletList = () => {
type: KEYRING_CLASS.HARDWARE.LEDGER,
logo: WALLET_BRAND_CONTENT[WALLET_BRAND_TYPES.LEDGER].icon,
},
{
type: KEYRING_CLASS.HARDWARE.BITBOX02,
logo: WALLET_BRAND_CONTENT[WALLET_BRAND_TYPES.BITBOX02].icon,
},
{
type: KEYRING_CLASS.HARDWARE.TREZOR,
logo: WALLET_BRAND_CONTENT[WALLET_BRAND_TYPES.TREZOR].icon,
Expand All @@ -55,11 +51,15 @@ export const ImportWalletList = () => {
type: KEYRING_CLASS.HARDWARE.GRIDPLUS,
logo: WALLET_BRAND_CONTENT[WALLET_BRAND_TYPES.GRIDPLUS].icon,
},
{
type: KEYRING_CLASS.HARDWARE.BITBOX02,
logo: WALLET_BRAND_CONTENT[WALLET_BRAND_TYPES.BITBOX02].icon,
},
{
type: KEYRING_CLASS.GNOSIS,
logo: WALLET_BRAND_CONTENT[WALLET_BRAND_TYPES.GNOSIS].icon,
},
].slice(0, !showMore ? 4 : undefined),
].slice(0, !showMore ? 3 : undefined),
[showMore]
);

Expand Down
Loading

0 comments on commit c0a2fc5

Please sign in to comment.