Skip to content

Commit

Permalink
feat(suite-native): debug prefilled send form address button
Browse files Browse the repository at this point in the history
  • Loading branch information
PeKne committed Oct 18, 2024
1 parent e448a04 commit d7c8594
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
10 changes: 10 additions & 0 deletions suite-native/accounts/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,13 @@ export const selectAccountListSections = memoizeWithArgs(
// Some reasonable number of accounts that could be in app
{ size: 40 },
);

export const selectFirstUnusedAccountAddress = (
state: NativeAccountsRootState,
accountKey: AccountKey,
) => {
const account = selectAccountByKey(state, accountKey);
if (!account) return null;

return account.addresses?.unused[0]?.address ?? null;
};
1 change: 1 addition & 0 deletions suite-native/module-send/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@suite-native/alerts": "workspace:*",
"@suite-native/analytics": "workspace:*",
"@suite-native/atoms": "workspace:*",
"@suite-native/config": "workspace:*",
"@suite-native/device": "workspace:*",
"@suite-native/device-mutex": "workspace:*",
"@suite-native/formatters": "workspace:*",
Expand Down
25 changes: 21 additions & 4 deletions suite-native/module-send/src/components/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import React from 'react';
import { useSelector } from 'react-redux';

import { formInputsMaxLength } from '@suite-common/validators';
import { VStack, Text } from '@suite-native/atoms';
import { VStack, Text, HStack, Button } from '@suite-native/atoms';
import { TextInputField, useFormContext } from '@suite-native/forms';
import { Translation } from '@suite-native/intl';
import { analytics, EventType } from '@suite-native/analytics';
import { isAddressValid } from '@suite-common/wallet-utils';
import { AccountKey } from '@suite-common/wallet-types';
import { AccountsRootState, selectAccountNetworkSymbol } from '@suite-common/wallet-core';
import { NativeAccountsRootState, selectFirstUnusedAccountAddress } from '@suite-native/accounts';
import { isDebugEnv } from '@suite-native/config';

import { QrCodeBottomSheetIcon } from './QrCodeBottomSheetIcon';
import { getOutputFieldName } from '../utils';
Expand All @@ -24,6 +26,9 @@ export const AddressInput = ({ index, accountKey }: AddressInputProps) => {
const networkSymbol = useSelector((state: AccountsRootState) =>
selectAccountNetworkSymbol(state, accountKey),
);
const unusedAccountAddress = useSelector((state: NativeAccountsRootState) =>
selectFirstUnusedAccountAddress(state, accountKey),
);

const handleScanAddressQRCode = (qrCodeData: string) => {
setValue(addressFieldName, qrCodeData, { shouldValidate: true });
Expand All @@ -38,11 +43,23 @@ export const AddressInput = ({ index, accountKey }: AddressInputProps) => {
}
};

// Debug helper to fill opened account address.
const fillSelfAddress = () => {
setValue(addressFieldName, unusedAccountAddress, { shouldValidate: true });
};

return (
<VStack spacing="sp12">
<Text variant="hint">
<Translation id="moduleSend.outputs.recipients.addressLabel" />
</Text>
<HStack flex={1} justifyContent="space-between" alignItems="center">
<Text variant="hint">
<Translation id="moduleSend.outputs.recipients.addressLabel" />
</Text>
{isDebugEnv() && (
<Button size="small" colorScheme="tertiaryElevation0" onPress={fillSelfAddress}>
self address
</Button>
)}
</HStack>
<TextInputField
multiline
name={addressFieldName}
Expand Down
1 change: 1 addition & 0 deletions suite-native/module-send/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
{ "path": "../alerts" },
{ "path": "../analytics" },
{ "path": "../atoms" },
{ "path": "../config" },
{ "path": "../device" },
{ "path": "../device-mutex" },
{ "path": "../formatters" },
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10397,6 +10397,7 @@ __metadata:
"@suite-native/alerts": "workspace:*"
"@suite-native/analytics": "workspace:*"
"@suite-native/atoms": "workspace:*"
"@suite-native/config": "workspace:*"
"@suite-native/device": "workspace:*"
"@suite-native/device-mutex": "workspace:*"
"@suite-native/formatters": "workspace:*"
Expand Down

0 comments on commit d7c8594

Please sign in to comment.