Skip to content

Commit b7a7688

Browse files
committed
Fix nullable acts
1 parent 400707d commit b7a7688

File tree

10 files changed

+27
-21
lines changed

10 files changed

+27
-21
lines changed

src/modules/ethereum/transactions/addressAction/addressActionMain.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@ export type LocalActionTransaction = Omit<
2424
hash: string | null;
2525
};
2626

27-
type LocalAct = Omit<AddressAction['acts'][number], 'transaction'> & {
27+
type LocalAct = Omit<
28+
NonNullable<AddressAction['acts']>[number],
29+
'transaction'
30+
> & {
2831
transaction: LocalActionTransaction;
2932
};
3033

3134
export type LocalAddressAction = Omit<AddressAction, 'transaction' | 'acts'> & {
32-
acts: LocalAct[];
35+
acts: LocalAct[] | null;
3336
transaction: LocalActionTransaction | null;
3437
rawTransaction: {
3538
data?: string | null;
@@ -648,7 +651,7 @@ export function createCancelAddressAction(
648651

649652
export function getActionApprovalFungibleId(action: AnyAddressAction) {
650653
return (
651-
(action?.acts.length === 1 &&
654+
(action?.acts?.length === 1 &&
652655
action.acts[0].content?.approvals?.length === 1 &&
653656
!action.acts[0].content.transfers
654657
? action.acts[0].content.approvals[0].fungible?.id

src/modules/zerion-api/requests/wallet-get-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ type Action = {
273273
};
274274
/** @description Gasback amount if applicable (when network fee is not free) */
275275
gasback: null | number;
276-
acts: Act[];
276+
acts: Act[] | null;
277277
content: Content | null;
278278
transaction: ActionTransaction | null;
279279
};

src/shared/analytics/shared/addressActionToAnalytics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ export function addressActionToAnalytics({
4343
};
4444
}
4545
const outgoing = addressAction.acts
46-
.at(0)
46+
?.at(0)
4747
?.content?.transfers?.filter(({ direction }) => direction === 'out');
4848
const incoming = addressAction.acts
49-
.at(0)
49+
?.at(0)
5050
?.content?.transfers?.filter(({ direction }) => direction === 'in');
5151

5252
const value = {

src/ui/components/address-action/ActInfo/ActInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export function ActInfo({
154154
elementEnd,
155155
}: {
156156
address: string;
157-
act: AnyAddressAction['acts'][number];
157+
act: NonNullable<AnyAddressAction['acts']>[number];
158158
initialDelay: number;
159159
elementEnd: React.ReactNode;
160160
}) {

src/ui/components/address-action/AddressActionDetails/AddressActionDetails.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ export function AddressActionDetails({
3434
const actionWithAppliedAllowance = useMemo(() => {
3535
if (
3636
allowanceQuantityCommon == null ||
37-
addressAction?.acts.length !== 1 ||
37+
addressAction?.acts?.length !== 1 ||
3838
addressAction.acts[0].content?.approvals?.length !== 1
3939
) {
4040
return addressAction;
4141
}
4242
return produce(addressAction, (draft) => {
43-
if (draft.acts[0].content?.approvals?.[0].amount) {
43+
if (draft.acts?.[0].content?.approvals?.[0].amount) {
4444
draft.acts[0].content.approvals[0].amount.quantity =
4545
allowanceQuantityCommon;
4646
draft.acts[0].content.approvals[0].unlimited = isUnlimitedApproval(
@@ -51,7 +51,7 @@ export function AddressActionDetails({
5151
}, [addressAction, allowanceQuantityCommon, customAllowanceQuantityBase]);
5252

5353
const showEndElement =
54-
addressAction?.acts.length === 1 &&
54+
addressAction?.acts?.length === 1 &&
5555
!addressAction.acts[0].content?.transfers &&
5656
addressAction.acts[0].content?.approvals?.length === 1;
5757

src/ui/components/address-action/TransactionSimulation/TransactionSimulation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export function TransactionSimulation({
122122
interpretAddressAction || localEvmAddressAction || localSolanaAddressAction;
123123

124124
const requestedAllowanceQuantityCommon = addressAction?.acts
125-
.at(0)
125+
?.at(0)
126126
?.content?.approvals?.at(0)?.amount?.quantity;
127127

128128
const approvalFungibleId = addressAction

src/ui/pages/ActionInfo/ActionInfo.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ function ActContent({
196196
act,
197197
showActType,
198198
}: {
199-
act: AddressAction['acts'][number];
199+
act: NonNullable<AddressAction['acts']>[number];
200200
showActType: boolean;
201201
}) {
202202
const approvals = act.content?.approvals;
@@ -309,7 +309,7 @@ export function ActionInfo() {
309309
const actIndex = act_index ? Number(act_index) : undefined;
310310
const addressAction = state.addressAction as AddressAction | undefined;
311311
const targetObject =
312-
actIndex != null ? addressAction?.acts.at(actIndex) : addressAction;
312+
actIndex != null ? addressAction?.acts?.at(actIndex) : addressAction;
313313

314314
const actionDate = useMemo(() => {
315315
return addressAction?.timestamp
@@ -346,15 +346,15 @@ export function ActionInfo() {
346346
/>
347347
<VStack gap={16} style={{ marginTop: 16 }}>
348348
<VStack gap={8}>
349-
{actIndex != null && addressAction?.acts[actIndex] ? (
349+
{actIndex != null && addressAction?.acts?.at(actIndex) ? (
350350
<ActContent
351351
act={addressAction.acts[actIndex]}
352352
showActType={false}
353353
/>
354-
) : addressAction.acts.length === 1 ? (
354+
) : addressAction.acts?.length === 1 ? (
355355
<ActContent act={addressAction.acts[0]} showActType={false} />
356356
) : (
357-
addressAction?.acts.map((act, index) => (
357+
addressAction?.acts?.map((act, index) => (
358358
<div
359359
key={index}
360360
className={styles.act}

src/ui/pages/History/ActionsList/ActionsList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function ActionsList({
5151
items={items.map((addressAction) => {
5252
const hash =
5353
addressAction.transaction?.hash ||
54-
addressAction.acts.at(0)?.transaction.hash ||
54+
addressAction.acts?.at(0)?.transaction.hash ||
5555
'';
5656
return {
5757
key: isLocalAddressAction(addressAction)

src/ui/pages/History/History.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ function mergeLocalAndBackendActions(
5252
hasMoreBackendActions: boolean
5353
) {
5454
const backendHashes = new Set(
55-
backend.map((tx) => tx.transaction?.hash || tx.acts[0].transaction.hash)
55+
backend.map(
56+
(tx) => tx.transaction?.hash || tx.acts?.at(0)?.transaction.hash
57+
)
5658
);
5759

5860
const lastBackendActionDatetime = backend.at(-1)?.timestamp;
@@ -66,7 +68,7 @@ function mergeLocalAndBackendActions(
6668
(tx) =>
6769
tx.transaction?.hash &&
6870
backendHashes.has(tx.transaction.hash) === false &&
69-
!tx.acts.some(
71+
!tx.acts?.some(
7072
(act) =>
7173
act.transaction.hash && backendHashes.has(act.transaction.hash)
7274
) &&

src/ui/pages/SendTransaction/SendTransaction.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,9 +756,10 @@ function SendTransactionContent({
756756
});
757757

758758
const requestedAllowanceQuantityCommon =
759-
interpretQuery.data?.action?.acts.at(0)?.content?.approvals?.at(0)?.amount
759+
interpretQuery.data?.action?.acts?.at(0)?.content?.approvals?.at(0)?.amount
760760
?.quantity ||
761-
localAddressAction?.acts.at(0)?.content?.approvals?.at(0)?.amount?.quantity;
761+
localAddressAction?.acts?.at(0)?.content?.approvals?.at(0)?.amount
762+
?.quantity;
762763

763764
const requestedAllowanceQuantityBase =
764765
requestedAllowanceQuantityCommon && fungibleDecimals

0 commit comments

Comments
 (0)