Skip to content

Commit

Permalink
feat: new actions (#2491)
Browse files Browse the repository at this point in the history
* feat: new actions

* feat: rabby action

* feat: testnet

* fix: rabby-action

* fix: typed data actions

* feat: support 3 new actions (#2495)

* feat: + 3 new actions

* chore: remove useless code

* fix: TransactionActionList

* fix: rabby-action

* fix: common require data is null

---------

Co-authored-by: heisenberg <[email protected]>

* fix: type

* feat: + interact before

---------

Co-authored-by: vvvvvv1vvvvvv <[email protected]>
Co-authored-by: vvvvvv1vvvvvv <[email protected]>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent b340053 commit 8134131
Show file tree
Hide file tree
Showing 57 changed files with 1,277 additions and 3,220 deletions.
9 changes: 9 additions & 0 deletions _raw/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@
},
"wrapToken": "Wrap Token",
"unwrap": "Unwrap Token",
"transferOwner": {
"title": "Transfer Assets Ownership",
"description": "Description",
"transferTo": "Transfer to"
},
"swapLimitPay": {
"title": "Swap Token Limit Pay",
"maxPay": "Maximum pay"
},
"send": {
"title": "Send Token",
"sendToken": "Send token",
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@
"@rabby-wallet/eth-watch-keyring": "1.0.0",
"@rabby-wallet/gnosis-sdk": "1.3.8",
"@rabby-wallet/page-provider": "0.4.0",
"@rabby-wallet/rabby-api": "0.7.27",
"@rabby-wallet/rabby-security-engine": "^2.0.6-beta.1",
"@rabby-wallet/rabby-action": "^0.1.1-beta.3",
"@rabby-wallet/rabby-api": "0.7.28",
"@rabby-wallet/rabby-security-engine": "2.0.7-beta",
"@rabby-wallet/rabby-swap": "0.0.39",
"@rabby-wallet/widgets": "1.0.9",
"@rematch/core": "2.2.0",
Expand Down
21 changes: 9 additions & 12 deletions src/background/service/transactionHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@ import openapiService, {
testnetOpenapiService,
TxRequest,
} from './openapi';
import { CHAINS, INTERNAL_REQUEST_ORIGIN, CHAINS_ENUM, EVENTS } from 'consts';
import { INTERNAL_REQUEST_ORIGIN, CHAINS_ENUM, EVENTS } from 'consts';
import stats from '@/stats';
import permissionService, { ConnectedSite } from './permission';
import { nanoid } from 'nanoid';
import { findChain, findChainByID } from '@/utils/chain';
import { makeTransactionId } from '@/utils/transaction';
import {
ActionRequireData,
ParsedActionData,
} from '@/ui/views/Approval/components/Actions/utils';
import { sortBy, max, groupBy } from 'lodash';
import { sortBy, groupBy } from 'lodash';
import { checkIsPendingTxGroup, findMaxGasTx } from '@/utils/tx';
import eventBus from '@/eventBus';
import { customTestnetService } from './customTestnet';
import { isManifestV3 } from '@/utils/env';
import browser from 'webextension-polyfill';
import { ALARMS_RELOAD_TX } from '../utils/alarms';
import {
ActionRequireData,
ParsedTransactionActionData,
} from '@rabby-wallet/rabby-action';

export interface TransactionHistoryItem {
rawTx: Tx;
Expand All @@ -51,7 +48,7 @@ export interface TransactionSigningItem {
{ approvalId: string; calcSuccess: boolean }
>;
action?: {
actionData: ParsedActionData;
actionData: ParsedTransactionActionData;
requiredData: ActionRequireData;
};
id: string;
Expand All @@ -69,7 +66,7 @@ export interface TransactionGroup {
{ approvalId: string; calcSuccess: boolean }
>;
action?: {
actionData: ParsedActionData;
actionData: ParsedTransactionActionData;
requiredData: ActionRequireData;
};
isFailed: boolean;
Expand Down Expand Up @@ -122,7 +119,7 @@ class TxHistory {
explain?: Partial<TransactionSigningItem['explain']>;
rawTx?: Partial<TransactionSigningItem['rawTx']>;
action?: {
actionData: ParsedActionData;
actionData: ParsedTransactionActionData;
requiredData: ActionRequireData;
};
isSubmitted?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/constant/default-support-chains.json

Large diffs are not rendered by default.

44 changes: 29 additions & 15 deletions src/ui/utils/sendTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {
ALIAS_ADDRESS,
CHAINS_ENUM,
EVENTS,
INTERNAL_REQUEST_ORIGIN,
INTERNAL_REQUEST_SESSION,
} from '@/constant';
import { intToHex, WalletControllerType } from '@/ui/utils';
import { findChain } from '@/utils/chain';
import { findChain, isTestnet } from '@/utils/chain';
import {
calcGasLimit,
calcMaxPriorityFee,
Expand All @@ -16,12 +17,12 @@ import {
} from '@/utils/transaction';
import { GasLevel, Tx, TxPushType } from '@rabby-wallet/rabby-api/dist/types';
import BigNumber from 'bignumber.js';
import {
fetchActionRequiredData,
parseAction,
} from '@/ui/views/Approval/components/Actions/utils';
import Browser from 'webextension-polyfill';
import eventBus from '@/eventBus';
import {
parseAction,
fetchActionRequiredData,
} from '@rabby-wallet/rabby-action';

// fail code
export enum FailedCode {
Expand Down Expand Up @@ -240,31 +241,44 @@ export const sendTransaction = async ({
origin: origin || '',
addr: address,
});
const parsed = parseAction(
actionData.action,
preExecResult.balance_change,
{
const parsed = parseAction({
type: 'transaction',
data: actionData.action,
balanceChange: preExecResult.balance_change,
tx: {
...tx,
gas: '0x0',
nonce: recommendNonce || '0x1',
value: tx.value || '0x0',
},
preExecResult.pre_exec_version,
preExecResult.gas.gas_used
);
preExecVersion: preExecResult.pre_exec_version,
gasUsed: preExecResult.gas.gas_used,
sender: tx.from,
});
const requiredData = await fetchActionRequiredData({
type: 'transaction',
actionData: parsed,
contractCall: actionData.contract_call,
chainId: chain.serverId,
address,
wallet,
sender: address,
walletProvider: {
hasPrivateKeyInWallet: wallet.hasPrivateKeyInWallet,
hasAddress: wallet.hasAddress,
getWhitelist: wallet.getWhitelist,
isWhitelistEnabled: wallet.isWhitelistEnabled,
getPendingTxsByNonce: wallet.getPendingTxsByNonce,
findChain,
ALIAS_ADDRESS,
},
tx: {
...tx,
gas: '0x0',
nonce: recommendNonce || '0x1',
value: tx.value || '0x0',
},
origin,
apiProvider: isTestnet(chain.serverId)
? wallet.testnetOpenapi
: wallet.openapi,
});

await wallet.updateSigningTx(signingTxId, {
Expand Down
7 changes: 5 additions & 2 deletions src/ui/views/Approval/components/Actions/ApproveNFT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import styled from 'styled-components';
import { useTranslation } from 'react-i18next';
import { Chain } from 'background/service/openapi';
import { Result } from '@rabby-wallet/rabby-security-engine';
import { ApproveNFTRequireData, ParsedActionData } from './utils';
import {
ApproveNFTRequireData,
ParsedTransactionActionData,
} from '@rabby-wallet/rabby-action';
import { useRabbyDispatch } from '@/ui/store';
import { Table, Col, Row } from './components/Table';
import NFTWithName from './components/NFTWithName';
Expand Down Expand Up @@ -52,7 +55,7 @@ const ApproveNFT = ({
chain,
engineResults,
}: {
data: ParsedActionData['approveNFT'];
data: ParsedTransactionActionData['approveNFT'];
requireData: ApproveNFTRequireData;
chain: Chain;
engineResults: Result[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import styled from 'styled-components';
import { useTranslation } from 'react-i18next';
import { Chain } from 'background/service/openapi';
import { Result } from '@rabby-wallet/rabby-security-engine';
import { ApproveNFTRequireData, ParsedActionData } from './utils';
import {
ApproveNFTRequireData,
ParsedTransactionActionData,
} from '@rabby-wallet/rabby-action';
import { useRabbyDispatch } from '@/ui/store';
import { Table, Col, Row } from './components/Table';
import * as Values from './components/Values';
Expand Down Expand Up @@ -51,7 +54,7 @@ const ApproveNFTCollection = ({
chain,
engineResults,
}: {
data: ParsedActionData['approveNFTCollection'];
data: ParsedTransactionActionData['approveNFTCollection'];
requireData: ApproveNFTRequireData;
chain: Chain;
engineResults: Result[];
Expand Down
8 changes: 5 additions & 3 deletions src/ui/views/Approval/components/Actions/AssetOrder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import styled from 'styled-components';
import { useTranslation } from 'react-i18next';
import { Chain } from 'background/service/openapi';
import { Result } from '@rabby-wallet/rabby-security-engine';
import { ContractRequireData } from '../TypedDataActions/utils';
import { ParsedActionData } from './utils';
import { isSameAddress } from 'ui/utils';
import { useRabbyDispatch, useRabbySelector } from '@/ui/store';
import { Table, Col, Row } from '../Actions/components/Table';
Expand All @@ -16,6 +14,10 @@ import { ProtocolListItem } from '../Actions/components/ProtocolListItem';
import LogoWithText from '../Actions/components/LogoWithText';
import SecurityLevelTagNoText from '../SecurityEngine/SecurityLevelTagNoText';
import { SubCol, SubRow, SubTable } from './components/SubTable';
import {
ContractRequireData,
ParsedTransactionActionData,
} from '@rabby-wallet/rabby-action';

const Wrapper = styled.div`
.header {
Expand Down Expand Up @@ -57,7 +59,7 @@ const AssetOrder = ({
engineResults,
sender,
}: {
data: ParsedActionData['assetOrder'];
data: ParsedTransactionActionData['assetOrder'];
requireData: ContractRequireData;
chain: Chain;
engineResults: Result[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import styled from 'styled-components';
import { useTranslation } from 'react-i18next';
import { Chain, RevokeTokenApproveAction } from 'background/service/openapi';
import { Result } from '@rabby-wallet/rabby-security-engine';
import { ParsedActionData, BatchRevokePermit2RequireData } from './utils';
import {
BatchRevokePermit2RequireData,
ParsedTransactionActionData,
} from '@rabby-wallet/rabby-action';
import { Table, Col, Row } from './components/Table';
import LogoWithText from './components/LogoWithText';
import * as Values from './components/Values';
Expand Down Expand Up @@ -35,7 +38,7 @@ export const BatchRevokePermit2 = ({
requireData,
chain,
}: {
data: ParsedActionData['permit2BatchRevokeToken'];
data: ParsedTransactionActionData['permit2BatchRevokeToken'];
requireData: BatchRevokePermit2RequireData;
chain: Chain;
raw?: Record<string, string | number>;
Expand Down
14 changes: 7 additions & 7 deletions src/ui/views/Approval/components/Actions/CancelTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { Chain } from 'background/service/openapi';
import { Result } from '@rabby-wallet/rabby-security-engine';
import { maxBy } from 'lodash';
import { useTranslation } from 'react-i18next';
import {
ParsedActionData,
CancelTxRequireData,
getActionTypeText,
} from './utils';
import { getActionTypeText } from './utils';
import { useRabbyDispatch } from '@/ui/store';
import IconAlert from 'ui/assets/sign/tx/alert.svg';
import {
CancelTxRequireData,
ParsedTransactionActionData,
} from '@rabby-wallet/rabby-action';

const Wrapper = styled.div`
.container {
Expand Down Expand Up @@ -82,7 +82,7 @@ const CancelTx = ({
requireData,
raw,
}: {
data: ParsedActionData['cancelTx'];
data: ParsedTransactionActionData['cancelTx'];
requireData: CancelTxRequireData;
chain: Chain;
raw: Record<string, string | number>;
Expand All @@ -98,7 +98,7 @@ const CancelTx = ({
let type = t('page.signTx.unknownAction');
if (group.action) {
const data = group.action.actionData;
type = getActionTypeText(data);
type = getActionTypeText(data as ParsedTransactionActionData);
}
const target = maxBy(group.txs, (item) =>
Number(item.rawTx.gasPrice || item.rawTx.maxFeePerGas || 0)
Expand Down
7 changes: 5 additions & 2 deletions src/ui/views/Approval/components/Actions/ContractCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import BigNumber from 'bignumber.js';
import { useTranslation } from 'react-i18next';
import { Chain } from 'background/service/openapi';
import { Result } from '@rabby-wallet/rabby-security-engine';
import { ContractCallRequireData, ParsedActionData } from './utils';
import {
ContractCallRequireData,
ParsedTransactionActionData,
} from '@rabby-wallet/rabby-action';
import { formatTokenAmount } from 'ui/utils/number';
import { useRabbyDispatch, useRabbySelector } from '@/ui/store';
import { Table, Col, Row } from './components/Table';
Expand Down Expand Up @@ -58,7 +61,7 @@ const ContractCall = ({
chain,
engineResults,
}: {
data: ParsedActionData['contractCall'];
data: ParsedTransactionActionData['contractCall'];
requireData: ContractCallRequireData;
chain: Chain;
raw: Record<string, string | number>;
Expand Down
7 changes: 5 additions & 2 deletions src/ui/views/Approval/components/Actions/CrossSwapToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { Table, Col, Row } from './components/Table';
import LogoWithText from './components/LogoWithText';
import * as Values from './components/Values';
import ViewMore from './components/ViewMore';
import { ParsedActionData, SwapRequireData } from './utils';
import {
SwapRequireData,
ParsedTransactionActionData,
} from '@rabby-wallet/rabby-action';
import { formatAmount, formatUsdValue } from 'ui/utils/number';
import { Chain } from 'background/service/openapi';
import SecurityLevelTagNoText from '../SecurityEngine/SecurityLevelTagNoText';
Expand Down Expand Up @@ -41,7 +44,7 @@ const CrossSwapToken = ({
chain,
engineResults,
}: {
data: ParsedActionData['crossSwapToken'];
data: ParsedTransactionActionData['crossSwapToken'];
requireData: SwapRequireData;
chain: Chain;
engineResults: Result[];
Expand Down
7 changes: 5 additions & 2 deletions src/ui/views/Approval/components/Actions/CrossToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { Table, Col, Row } from './components/Table';
import LogoWithText from './components/LogoWithText';
import * as Values from './components/Values';
import ViewMore from './components/ViewMore';
import { ParsedActionData, SwapRequireData } from './utils';
import {
SwapRequireData,
ParsedTransactionActionData,
} from '@rabby-wallet/rabby-action';
import { formatAmount, formatUsdValue } from 'ui/utils/number';
import { Chain } from 'background/service/openapi';
import SecurityLevelTagNoText from '../SecurityEngine/SecurityLevelTagNoText';
Expand Down Expand Up @@ -41,7 +44,7 @@ const Swap = ({
chain,
engineResults,
}: {
data: ParsedActionData['crossToken'];
data: ParsedTransactionActionData['crossToken'];
requireData: SwapRequireData;
chain: Chain;
engineResults: Result[];
Expand Down
Loading

0 comments on commit 8134131

Please sign in to comment.