Skip to content

Commit

Permalink
Merge pull request #9487 from hicommonwealth/kaleemNeslit.9244.copy_w…
Browse files Browse the repository at this point in the history
…allet_address

Kaleem neslit.9244.copy wallet address
  • Loading branch information
Kaleem Neslit authored Oct 11, 2024
2 parents 4f2bb56 + f838302 commit 6884d90
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
padding: 0 !important;
max-height: 24px;
line-height: 14px;
display: flex !important;

&.cwsl__value-container--is-multi {
max-height: initial !important;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useEffect, useState } from 'react';
import { useFormContext } from 'react-hook-form';
import type { GroupBase, Props } from 'react-select';
import type { GroupBase, Props, SingleValueProps } from 'react-select';
import Select from 'react-select';
import { getClasses } from '../../helpers';
import { ComponentType } from '../../types';
import { CWSingleSelectItem } from '../CWSingleSelectItem/CWSingleSelectItem';
import { MessageRow } from '../CWTextInput/MessageRow';
import './CWSelectList.scss';
import { DropdownIndicator } from './DropdownIndicator';
Expand All @@ -14,8 +15,18 @@ type CustomCWSelectListProps = {
label?: string;
hookToForm?: boolean;
customError?: string;
// eslint-disable-next-line prettier/prettier
saveToClipboard?: (
id: string,
successNotification?: boolean,
) => Promise<void>;
showCopyIcon?: boolean;
};

type OptionProps = {
value: string;
label: string;
};
export const CWSelectList = <
Option,
IsMulti extends boolean = false,
Expand All @@ -35,6 +46,8 @@ export const CWSelectList = <
customError,
components,
isMulti,
showCopyIcon,
saveToClipboard,
} = props;
const formContext = useFormContext();
const formFieldContext = hookToForm
Expand Down Expand Up @@ -124,6 +137,16 @@ export const CWSelectList = <
DropdownIndicator,
MultiValueRemove,
Option: components?.Option || Option,
...(showCopyIcon && {
// eslint-disable-next-line react/no-multi-comp
SingleValue: (singleValueProps: SingleValueProps<OptionProps>) => (
<CWSingleSelectItem
{...singleValueProps}
showCopyIcon={showCopyIcon}
saveToClipboard={saveToClipboard}
/>
),
}),
}}
className={getClasses<{
className?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@import '../../../../../../styles/shared.scss';
.CWSingleSelectItem {
display: flex;
width: 97%;
justify-content: space-between;
align-items: center;
padding-right: 4px;
cursor: pointer;

.inner-container {
display: flex;

.check-icon {
fill: $green-600;
margin-right: 8px;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { CopySimple } from '@phosphor-icons/react';
import { formatAddressShort } from 'client/scripts/helpers';
import React from 'react';
import { SingleValueProps } from 'react-select';
import { CWIcon } from '../../cw_icons/cw_icon';
import './CWSingleSelectItem.scss';
type CustomSingleValueProps = {
showCopyIcon?: boolean;
// eslint-disable-next-line prettier/prettier
saveToClipboard?: (
id: string,
successNotification?: boolean,
) => Promise<void>;
};

type OptionProps = {
value: string;
label: string;
};

export const CWSingleSelectItem = (
props: SingleValueProps<OptionProps> & CustomSingleValueProps,
) => {
const { data, showCopyIcon = false, saveToClipboard } = props;

const handleClickToCopy = async (event: React.MouseEvent) => {
event.stopPropagation();
if (saveToClipboard) {
await saveToClipboard(data.value, true);
}
};

return (
<div className="CWSingleSelectItem">
{showCopyIcon && (
<div className="inner-container">
<CWIcon
className="check-icon"
iconSize="small"
iconName="checkCircleFilled"
/>
{formatAddressShort(data.label, 6)}
</div>
)}
{showCopyIcon && (
<CopySimple
size={20}
onMouseDown={(event) => {
void handleClickToCopy(event);
}}
/>
)}
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { commonProtocol } from '@hicommonwealth/shared';
import { saveToClipboard } from 'client/scripts/utils/clipboard';
import clsx from 'clsx';
import { findDenominationIcon } from 'helpers/findDenomination';
import { useBrowserAnalyticsTrack } from 'hooks/useBrowserAnalyticsTrack';
Expand Down Expand Up @@ -131,7 +132,7 @@ const StakeExchangeForm = ({
const { trackAnalytics } = useBrowserAnalyticsTrack<BaseMixpanelPayload>({
onAction: true,
});

// eslint-disable-next-line @typescript-eslint/no-floating-promises
const handleBuy = async () => {
try {
onSetModalState(ManageCommunityStakeModalState.Loading);
Expand Down Expand Up @@ -239,7 +240,7 @@ const StakeExchangeForm = ({
onSetNumberOfStakeToExchange((prevState) => prevState + 1);
};

const handleInput = (e) => {
const handleInput = (e: React.ChangeEvent<HTMLInputElement>) => {
const inputValue = e.target.value;
const numericValue = inputValue.replace(/[^0-9]/g, '');
const parsed = parseInt(numericValue);
Expand Down Expand Up @@ -329,6 +330,8 @@ const StakeExchangeForm = ({
isSearchable={false}
options={addressOptions}
onChange={onSetSelectedAddress}
saveToClipboard={saveToClipboard}
showCopyIcon={true}
/>

<div className="current-balance-row">
Expand Down

0 comments on commit 6884d90

Please sign in to comment.