Skip to content

Commit 991de3d

Browse files
Configurable "data" in Send Transactions (#815)
* Configurable "data" in Send Transactions * update preferences defaults * Use custom data input for native assets only * Use action title from simulation in confirmation view
1 parent 041d2e4 commit 991de3d

File tree

7 files changed

+62
-2
lines changed

7 files changed

+62
-2
lines changed

src/background/Wallet/WalletRecord.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ export class WalletRecordModel {
846846
showNetworkSwitchShortcut: true,
847847
overviewChain: '',
848848
configurableNonce: false,
849+
configurableTransactionData: false,
849850
invitationBannerDismissed: false,
850851
recentAddresses: [],
851852
mintDnaBannerDismissed: false,

src/background/Wallet/model/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ interface PublicPreferences {
4343
* Allow to configure nonce before signing transactions
4444
*/
4545
configurableNonce?: boolean;
46+
/** Custom field for "data" in Send Form */
47+
configurableTransactionData?: boolean;
4648
invitationBannerDismissed?: boolean;
4749
recentAddresses?: string[];
4850
mintDnaBannerDismissed?: boolean;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export function TransactionConfirmationView({
103103
borderRadius: 12,
104104
}}
105105
>
106-
<UIText kind="headline/h2">{title}</UIText>
106+
<UIText kind="headline/h2">
107+
{txInterpretQuery.data?.action?.type.display_value ?? title}
108+
</UIText>
107109
<HStack gap={8} alignItems="center">
108110
<WalletAvatar
109111
address={wallet.address}

src/ui/pages/SendForm/SendForm.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import { getError } from 'get-error';
6060
import type { AddressAction } from 'src/modules/zerion-api/requests/wallet-get-actions';
6161
import BigNumber from 'bignumber.js';
6262
import { useAssetFullInfo } from 'src/modules/zerion-api/hooks/useAssetFullInfo';
63+
import { FormFieldset } from 'src/ui/ui-kit/FormFieldset';
6364
import { TransactionConfiguration } from '../SendTransaction/TransactionConfiguration';
6465
import { NetworkSelect } from '../Networks/NetworkSelect';
6566
import { NetworkFeeLineInfo } from '../SendTransaction/TransactionConfiguration/TransactionConfiguration';
@@ -163,6 +164,8 @@ function SendFormComponent() {
163164
tokenChain = '',
164165
tokenValue = '',
165166
addressInputValue = '',
167+
data = '',
168+
tokenAssetCode = '',
166169
} = formState;
167170
const chain = tokenChain ? createChain(tokenChain) : null;
168171
const currentPosition = useCurrentPosition(formState, currentPositions);
@@ -210,6 +213,8 @@ function SendFormComponent() {
210213
supportsSponsoredTransactions: network?.supports_sponsored_transactions,
211214
});
212215

216+
const nativeAssetId = network?.native_asset?.id;
217+
const isNativeAsset = tokenAssetCode === nativeAssetId;
213218
const configuration = useMemo(() => toConfiguration(formState), [formState]);
214219

215220
const snapshotRef = useRef<{ state: SendFormState } | null>(null);
@@ -461,7 +466,7 @@ function SendFormComponent() {
461466
value={tokenValue}
462467
network={network}
463468
onChange={(value) => handleChange('tokenValue', value)}
464-
tokenAssetCode={formState.tokenAssetCode || null}
469+
tokenAssetCode={tokenAssetCode || null}
465470
currentItem={currentPosition ?? null}
466471
items={currentPositions}
467472
onAssetCodeChange={(value) =>
@@ -478,6 +483,41 @@ function SendFormComponent() {
478483
networkId={formState.tokenChain || null}
479484
/>
480485
) : null}
486+
{preferences?.configurableTransactionData &&
487+
isNativeAsset &&
488+
addressType === 'evm' ? (
489+
<FormFieldset
490+
title="Data"
491+
style={{ borderBottomRightRadius: 4 }}
492+
startInput={
493+
<textarea
494+
name="data"
495+
value={data}
496+
onChange={(event) => {
497+
handleChange('data', event.currentTarget.value);
498+
}}
499+
style={{
500+
border: 'none',
501+
outline: 'none',
502+
backgroundColor: 'transparent',
503+
fontSize: 'inherit',
504+
fontFamily: 'inherit',
505+
fontWeight: 'inherit',
506+
fontStyle: 'inherit',
507+
lineHeight: 'inherit',
508+
padding: 16,
509+
paddingTop: 0,
510+
width: 'calc(100% + 32px)',
511+
marginLeft: -16,
512+
marginBottom: -16,
513+
resize: 'vertical',
514+
}}
515+
rows={2}
516+
placeholder="0x..."
517+
/>
518+
}
519+
/>
520+
) : null}
481521
</VStack>
482522
</VStack>
483523
</form>

src/ui/pages/SendForm/shared/SendFormState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type SendFormState = {
1010
* @see SendFormState.addressInputValue
1111
*/
1212
to?: string;
13+
data?: string; // custom data
1314
tokenValue?: string;
1415
tokenChain?: string;
1516
tokenAssetCode?: string;

src/ui/pages/SendForm/shared/prepareSendData.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export async function prepareSendData(
170170
gasLimit,
171171
nftAmount,
172172
nftId,
173+
data,
173174
} = formState;
174175
if (!from || !to || !tokenChain) {
175176
return EMPTY_SEND_DATA;
@@ -225,6 +226,9 @@ export async function prepareSendData(
225226
getDecimals({ asset: position.asset, chain })
226227
).toFixed(),
227228
});
229+
if (data && isNativeAsset) {
230+
tx = { ...tx, data };
231+
}
228232
}
229233
if (gasLimit) {
230234
invariant(isNumeric(gasLimit), 'Gas limit must be numeric');

src/ui/pages/Settings/Settings.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,16 @@ function DeveloperTools() {
458458
</span>
459459
}
460460
/>
461+
<ToggleSettingLine
462+
text="Custom Data"
463+
checked={preferences?.configurableTransactionData ?? false}
464+
onChange={(event) => {
465+
setPreferences({
466+
configurableTransactionData: event.target.checked,
467+
});
468+
}}
469+
detailText={<span>Attach arbitrary data to Send transactions</span>}
470+
/>
461471
<ToggleSettingLine
462472
text="Recognizable Connect Buttons"
463473
checked={globalPreferences?.recognizableConnectButtons || false}

0 commit comments

Comments
 (0)