Skip to content

Commit

Permalink
Merge pull request #2749 from gamingumar/feat/GU-2745/repeat-transfer
Browse files Browse the repository at this point in the history
feat: #2745 add support of repeat transfer
  • Loading branch information
feruzm committed Sep 13, 2023
2 parents 9ebb960 + d1c2602 commit baa11fd
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,7 @@ export default EStyleSheet.create({
justifyContent: 'center',
alignItems: 'center',
},
repeatContainer: {
marginLeft: 5,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const WalletLineItem = ({
cancelable,
cancelling,
onCancelPress,
onRepeatPress,
}) => (
<TouchableOpacity onPress={onPress} disabled={!onPress} activeOpacity={0.8}>
<GrayWrapper isGray={index && index % 2 !== 0}>
Expand All @@ -43,10 +44,11 @@ const WalletLineItem = ({
styles.iconWrapper,
isCircleIcon && styles.circleIcon,
index && {
backgroundColor: `${index && index % 2 !== 0
? EStyleSheet.value('$white')
: EStyleSheet.value('$primaryLightBackground')
}`,
backgroundColor: `${
index && index % 2 !== 0
? EStyleSheet.value('$white')
: EStyleSheet.value('$primaryLightBackground')
}`,
},
]}
>
Expand Down Expand Up @@ -78,9 +80,6 @@ const WalletLineItem = ({
/>
</PopoverWrapper>
)}



</View>
)}
{!!description && (
Expand All @@ -102,18 +101,35 @@ const WalletLineItem = ({
</View>
)}

{!!cancelable && (<IconButton
backgroundColor="transparent"
name="cancel"
iconType="MaterialIcons"
size={20}
style={styles.cancelIcon}
onPress={() => {onCancelPress && onCancelPress()}}
color="#c1c5c7"
isLoading={cancelling}
/>
{!!cancelable && (
<IconButton
backgroundColor="transparent"
name="cancel"
iconType="MaterialIcons"
size={20}
style={styles.cancelIcon}
onPress={() => {
onCancelPress && onCancelPress();
}}
color="#c1c5c7"
isLoading={cancelling}
/>
)}

{!!onRepeatPress && (
<IconButton
backgroundColor="transparent"
name="repeat"
iconType="FontAwesome"
size={18}
onPress={() => {
onRepeatPress();
}}
color="#c1c5c7"
isLoading={false}
style={styles.repeatContainer}
/>
)}

{isHasdropdown && (
<View style={styles.dropdownWrapper}>
Expand Down
20 changes: 12 additions & 8 deletions src/components/transaction/transactionView.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ import { getTimeFromNow } from '../../utils/time';
import { WalletLineItem } from '../basicUIElements';
import { getHumanReadableKeyString } from '../../utils/strings';

const TransactionView = ({ item, index, cancelling, onCancelPress}) => {
const TransactionView = ({ item, index, cancelling, onCancelPress, onRepeatPress }) => {
const intl = useIntl();
const [collapsed, setCollapsed] = useState(true);

const title = !!intl.messages[`wallet.${item.textKey}`] ?
intl.formatMessage({
id: `wallet.${item.textKey}`,
})
:
getHumanReadableKeyString(item.textKey)
const title = !!intl.messages[`wallet.${item.textKey}`]
? intl.formatMessage({
id: `wallet.${item.textKey}`,
})
: getHumanReadableKeyString(item.textKey);

const _onRepeatPress = () => {
if (onRepeatPress) {
onRepeatPress();
}
};

const _cardHeader = (
<WalletLineItem
Expand All @@ -45,7 +49,7 @@ const TransactionView = ({ item, index, cancelling, onCancelPress}) => {
cancelable={item.cancelable}
cancelling={cancelling}
onCancelPress={onCancelPress}

onRepeatPress={item.textKey === 'transfer' ? _onRepeatPress : undefined}
/>
);

Expand Down
16 changes: 14 additions & 2 deletions src/containers/transferContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class TransferContainer extends Component {
referredUsername: props.route.params?.referredUsername,
selectedAccount: props.currentAccount,
spkMarkets: [],
initialAmount: props.route.params?.initialAmount,
initialMemo: props.route.params?.initialMemo,
};
}

Expand Down Expand Up @@ -332,8 +334,16 @@ class TransferContainer extends Component {
dispatch,
route,
} = this.props;
const { balance, fundType, selectedAccount, tokenAddress, referredUsername, spkMarkets } =
this.state;
const {
balance,
fundType,
selectedAccount,
tokenAddress,
referredUsername,
spkMarkets,
initialAmount,
initialMemo,
} = this.state;

const transferType = route.params?.transferType ?? '';

Expand All @@ -358,6 +368,8 @@ class TransferContainer extends Component {
accountType: get(selectedAccount || currentAccount, 'local.authType'),
currentAccountName: get(currentAccount, 'name'),
setWithdrawVestingRoute: this._setWithdrawVestingRoute,
initialAmount,
initialMemo,
})
);
}
Expand Down
39 changes: 27 additions & 12 deletions src/screens/assetDetails/children/activitiesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import styles from './children.styles';
import { limitOrderCancel } from '../../../providers/hive-trade/hiveTrade';
import { useQueryClient } from '@tanstack/react-query';
import QUERIES from '../../../providers/queries/queryKeys';
import TransferTypes from '../../../constants/transferTypes';

interface ActivitiesListProps {
header: ComponentType<any> | ReactElement<any, string | JSXElementConstructor<any>>;
Expand All @@ -19,6 +20,7 @@ interface ActivitiesListProps {
activitiesEnabled: boolean;
onEndReached: () => void;
onRefresh: () => void;
onActionPress: (transferType: string, extraParams?: any) => void;
}

const ActivitiesList = ({
Expand All @@ -30,35 +32,48 @@ const ActivitiesList = ({
activitiesEnabled,
onEndReached,
onRefresh,
onActionPress,
}: ActivitiesListProps) => {
const intl = useIntl();

const queryClient = useQueryClient();
const isDarkTheme = useAppSelector((state) => state.ui.isDarkTheme);
const currentAccount = useAppSelector((state) => state.account.currentAccount );
const currentAccount = useAppSelector((state) => state.account.currentAccount);
const pinHash = useAppSelector((state) => state.application.pin);

const [cancellingTrxIndex, setCancellingTrxIndex] = useState(-1);
const [cancellingTrxIndex, setCancellingTrxIndex] = useState(-1);


const _onCancelPress = async (trxId:number) => {
try{
if(trxId){
const _onCancelPress = async (trxId: number) => {
try {
if (trxId) {
setCancellingTrxIndex(trxId);
await limitOrderCancel(currentAccount, pinHash, trxId);
queryClient.invalidateQueries([QUERIES.WALLET.GET_PENDING_REQUESTS]);
setCancellingTrxIndex(-1);
}
} catch(err){
} catch (err) {
setCancellingTrxIndex(-1);
}


}
};

const _renderActivityItem = ({ item, index }) => {
const _onRepeatPress = async (item: CoinActivity) => {
if (onActionPress) {
onActionPress(TransferTypes.TRANSFER_TOKEN, item);
}
};

return <Transaction item={item} index={index} cancelling={cancellingTrxIndex === item.trxIndex} onCancelPress={()=>{_onCancelPress(item.trxIndex)}}/>;
const _renderActivityItem = ({ item, index }) => {
return (
<Transaction
item={item}
index={index}
cancelling={cancellingTrxIndex === item.trxIndex}
onCancelPress={() => {
_onCancelPress(item.trxIndex);
}}
onRepeatPress={() => _onRepeatPress(item)}
/>
);
};

const sections = [];
Expand Down
15 changes: 13 additions & 2 deletions src/screens/assetDetails/screen/assetDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { BasicHeader } from '../../../components';
import { CoinSummary } from '../children';
import styles from './screen.styles';
import ActivitiesList from '../children/activitiesList';
import { CoinActivity, CoinData, QuoteItem } from '../../../redux/reducers/walletReducer';
import { useAppSelector } from '../../../hooks';
import { CoinData, QuoteItem } from '../../../redux/reducers/walletReducer';
import RootNavigation from '../../../navigation/rootNavigation';
import ROUTES from '../../../constants/routeNames';
import { ASSET_IDS } from '../../../constants/defaultAssets';
import { DelegationsModal, MODES } from '../children/delegationsModal';
import TransferTypes from '../../../constants/transferTypes';
import { walletQueries } from '../../../providers/queries';
import parseToken from '../../../utils/parseToken';

export interface AssetDetailsScreenParams {
coinId: string;
Expand Down Expand Up @@ -104,7 +105,7 @@ const AssetDetailsScreen = ({ navigation, route }: AssetDetailsScreenProps) => {
}
};

const _onActionPress = (transferType: string) => {
const _onActionPress = (transferType: string, baseActivity: CoinActivity | null = null) => {
let navigateTo = ROUTES.SCREENS.TRANSFER;
let navigateParams = {};

Expand Down Expand Up @@ -148,6 +149,15 @@ const AssetDetailsScreen = ({ navigation, route }: AssetDetailsScreenProps) => {
};
}

if (baseActivity) {
navigateParams = {
...navigateParams,
referredUsername: baseActivity.details?.split(' ')[2]?.slice(1), // from @user1 to @user2
initialAmount: `${parseToken(baseActivity.value)}`,
initialMemo: baseActivity.memo,
};
}

if (isPinCodeOpen) {
RootNavigation.navigate({
name: ROUTES.SCREENS.PINCODE,
Expand Down Expand Up @@ -191,6 +201,7 @@ const AssetDetailsScreen = ({ navigation, route }: AssetDetailsScreenProps) => {
activitiesEnabled={!coinData?.isSpk}
onEndReached={_fetchDetails}
onRefresh={_onRefresh}
onActionPress={_onActionPress}
/>
<DelegationsModal ref={delegationsModalRef} />
</View>
Expand Down
6 changes: 5 additions & 1 deletion src/screens/transfer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import TransferView from './screen/transferScreen';
import AddressView from './screen/addressScreen';
import PowerDownView from './screen/powerDownScreen';
import DelegateView from './screen/delegateScreen';
import TransferTypes from '../../constants/transferTypes';

const Transfer = ({ navigation, route }) => (
<TransferContainer navigation={navigation} route={route}>
Expand All @@ -29,6 +28,8 @@ const Transfer = ({ navigation, route }) => (
dispatch,
referredUsername,
spkMarkets,
initialAmount,
initialMemo,
}) => {
switch (transferType) {
case 'delegate':
Expand Down Expand Up @@ -94,6 +95,9 @@ const Transfer = ({ navigation, route }) => (
currentAccountName={currentAccountName}
selectedAccount={selectedAccount}
spkMarkets={spkMarkets}
referredUsername={referredUsername || ''}
initialAmount={initialAmount || ''}
initialMemo={initialMemo || ''}
/>
);
}
Expand Down
Loading

0 comments on commit baa11fd

Please sign in to comment.