Skip to content

Commit

Permalink
feat: async fetch hasInteraction
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 committed Dec 18, 2024
1 parent 356ed60 commit f13f133
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@rabby-wallet/eth-watch-keyring": "1.0.0",
"@rabby-wallet/gnosis-sdk": "1.3.9",
"@rabby-wallet/page-provider": "0.4.2",
"@rabby-wallet/rabby-action": "0.1.8",
"@rabby-wallet/rabby-action": "0.2.0-beta.0",
"@rabby-wallet/rabby-api": "0.9.2",
"@rabby-wallet/rabby-security-engine": "2.0.7",
"@rabby-wallet/rabby-swap": "0.0.42",
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/Approval/components/Actions/ApproveNFT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const ApproveNFT = ({
<SubCol>
<SubRow isTitle>{t('page.signTx.interacted')}</SubRow>
<SubRow>
<Values.Boolean value={requireData.hasInteraction} />
<Values.Interacted value={requireData.hasInteraction} />
</SubRow>
</SubCol>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const ApproveNFTCollection = ({
<SubCol>
<SubRow isTitle>{t('page.signTx.interacted')}</SubRow>
<SubRow>
<Values.Boolean value={requireData.hasInteraction} />
<Values.Interacted value={requireData.hasInteraction} />
</SubRow>
</SubCol>

Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/Approval/components/Actions/ContractCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const ContractCall = ({
<SubCol>
<SubRow isTitle>{t('page.signTx.interacted')}</SubRow>
<SubRow>
<Values.Boolean value={requireData.hasInteraction} />
<Values.Interacted value={requireData.hasInteraction} />
</SubRow>
</SubCol>
{isInWhitelist && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ const CrossSwapToken = ({
<SubCol>
<SubRow isTitle>{t('page.signTx.interacted')}</SubRow>
<SubRow>
<Values.Boolean value={requireData.hasInteraction} />
<Values.Interacted value={requireData.hasInteraction} />
</SubRow>
</SubCol>
{isInWhitelist && (
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/Approval/components/Actions/MultiSwap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const MultiSwap = ({
<SubCol>
<SubRow isTitle>{t('page.signTx.interacted')}</SubRow>
<SubRow>
<Values.Boolean value={requireData.hasInteraction} />
<Values.Interacted value={requireData.hasInteraction} />
</SubRow>
</SubCol>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export const TransactionActionList: React.FC<{
raw,
isTypedData = false,
}) => {
React.useEffect(() => {
if (requireData && 'extraState' in requireData) {
requireData.extraState.hasInteraction?.();
}
}, []);

return (
<>
{data.swap && (
Expand Down
10 changes: 8 additions & 2 deletions src/ui/views/Approval/components/Actions/components/Values.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,17 @@ const DisplayChain = ({ chainServerId }: { chainServerId: string }) => {
);
};

const Interacted = ({ value }: { value: boolean }) => {
const Interacted = ({ value }: { value: boolean | null }) => {
const { t } = useTranslation();
return (
<span className="flex">
{value ? <>{t('page.signTx.yes')}</> : <>{t('page.signTx.no')}</>}
{value === null ? (
'loading'
) : value ? (
<>{t('page.signTx.yes')}</>
) : (
<>{t('page.signTx.no')}</>
)}
</span>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ContractData {
bornAt: number | null;
rank: number | null;
title?: string;
hasInteraction: boolean;
hasInteraction: boolean | null;
}

export interface Props {
Expand Down Expand Up @@ -67,7 +67,7 @@ export const ContractPopup: React.FC<Props> = ({ data }) => {
<Col>
<Row>{t('page.signTx.interacted')}</Row>
<Row>
<Values.Boolean value={data.hasInteraction} />
<Values.Interacted value={data.hasInteraction} />
</Row>
</Col>
<Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface NFTSpenderData {
isEOA: boolean;
isDanger: boolean | null;
isRevoke?: boolean;
hasInteraction: boolean;
hasInteraction: boolean | null;
}

export interface Props {
Expand Down Expand Up @@ -110,7 +110,7 @@ export const NFTSpenderPopup: React.FC<Props> = ({ data }) => {
<Col>
<Row>{t('page.signTx.interacted')}</Row>
<Row>
<Values.Boolean value={data.hasInteraction} />
<Values.Interacted value={data.hasInteraction} />
</Row>
</Col>
<Col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface SpenderData {
isEOA: boolean;
isDanger: boolean | null;
isRevoke?: boolean;
hasInteraction: boolean;
hasInteraction: boolean | null;
}

export interface Props {
Expand Down Expand Up @@ -110,7 +110,7 @@ export const SpenderPopup: React.FC<Props> = ({ data }) => {
<Col>
<Row>{t('page.signTx.interacted')}</Row>
<Row>
<Values.Boolean value={data.hasInteraction} />
<Values.Interacted value={data.hasInteraction} />
</Row>
</Col>
<Col>
Expand Down
10 changes: 5 additions & 5 deletions src/ui/views/Approval/components/SignTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ import { GasLessConfig } from './FooterBar/GasLessComponents';
import { adjustV } from '@/ui/utils/gnosis';
import { useGasAccountTxsCheck } from '../../GasAccount/hooks/checkTxs';
import {
fetchActionRequiredData,
parseAction,
formatSecurityEngineContext,
ActionRequireData,
ParsedTransactionActionData,
useFetchActionRequiredData,
} from '@rabby-wallet/rabby-action';

interface BasicCoboArgusInfo {
Expand Down Expand Up @@ -389,9 +389,6 @@ const SignTx = ({ params, origin }: SignTxProps) => {
},
});
const [actionData, setActionData] = useState<ParsedTransactionActionData>({});
const [actionRequireData, setActionRequireData] = useState<ActionRequireData>(
null
);
const { t } = useTranslation();
const [preprocessSuccess, setPreprocessSuccess] = useState(true);
const [chainId, setChainId] = useState<number>(
Expand Down Expand Up @@ -628,6 +625,10 @@ const SignTx = ({ params, origin }: SignTxProps) => {
}, [engineResults, currentTx]);

const isGasTopUp = tx.to?.toLowerCase() === GAS_TOP_UP_ADDRESS.toLowerCase();
const {
fetchActionRequiredData,
requiredData: actionRequireData,
} = useFetchActionRequiredData();

const gasExplainResponse = useExplainGas({
gasUsed,
Expand Down Expand Up @@ -869,7 +870,6 @@ const SignTx = ({ params, origin }: SignTxProps) => {
const result = await executeEngine(ctx);
setEngineResults(result);
setActionData(parsed);
setActionRequireData(requiredData);
const approval = await getApproval();

approval.signingTxId &&
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4769,10 +4769,10 @@
sinon-chrome "^3.0.1"
webextension-polyfill "0.7.0"

"@rabby-wallet/rabby-action@0.1.8":
version "0.1.8"
resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-action/-/rabby-action-0.1.8.tgz#05b258b628a224d51dc471e93117d4106024a916"
integrity sha512-K0euVX55tW2mbnudm3bHPAbbLYlnDQD5PgAvM1mwPPFHhF/Ve/U5MYdg1XERJPxkoXKqiVti46idFFB+s8sv7A==
"@rabby-wallet/rabby-action@0.2.0-beta.0":
version "0.2.0-beta.0"
resolved "https://registry.yarnpkg.com/@rabby-wallet/rabby-action/-/rabby-action-0.2.0-beta.0.tgz#50042266ac53207f5480fa1622fea4ee0f51df7c"
integrity sha512-TtQSG+saMZGLzMdYYIp88HFG5P54jjxRgbE+ttuY8nW+P00s+HS4Sas1NEG/0aPaXng6qosNORDXclC2XLHpqw==

"@rabby-wallet/[email protected]":
version "0.9.2"
Expand Down

0 comments on commit f13f133

Please sign in to comment.