Skip to content

Commit

Permalink
feat: GU-2746 add recurrent transfer option in UI, api call added
Browse files Browse the repository at this point in the history
  • Loading branch information
gamingumar committed Oct 25, 2023
1 parent 9dae709 commit 4c571b5
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 5 deletions.
5 changes: 5 additions & 0 deletions reactotron-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ const reactotron = Reactotron.setAsyncStorageHandler(AsyncStorage) // AsyncStora
.connect(); // let's connect!

export default reactotron;

export const log = (...rest) => {
Reactotron.log(...rest);
console.log(...rest);
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export interface TransferAmountInputSectionProps {
setMemo: (value: string) => void;
amount: string;
setAmount: (value: string) => void;
recurrence: string;
setRecurrence: (value: string) => void;
hsTransfer: boolean;
transferType: string;
selectedAccount: any;
Expand All @@ -36,6 +38,8 @@ const TransferAmountInputSection = ({
setMemo,
amount,
setAmount,
recurrence,
setRecurrence,
transferType,
fundType,
disableMinimum,
Expand Down Expand Up @@ -63,6 +67,9 @@ const TransferAmountInputSection = ({
if (state === 'memo') {
setMemo(_amount);
}
if (state === 'recurrence') {
setRecurrence(val);
}
};

const _renderInput = (placeholder, state, keyboardType, isTextArea) => (
Expand All @@ -76,6 +83,8 @@ const TransferAmountInputSection = ({
? amount
: state === 'memo'
? memo
: state === 'recurrence'
? recurrence
: ''
}
placeholder={placeholder}
Expand Down Expand Up @@ -124,8 +133,22 @@ const TransferAmountInputSection = ({
</TouchableOpacity>
)}
/>
{transferType === TransferTypes.RECURRENT_TRANSFER && (
<TransferFormItem
label={intl.formatMessage({ id: 'transfer.recurrence' })}
rightComponent={() =>
_renderInput(
intl.formatMessage({ id: 'transfer.recurrence_placeholder' }),
'recurrence',
'numeric',
false,
)
}
/>
)}
{(transferType === TransferTypes.POINTS ||
transferType === TransferTypes.TRANSFER_TOKEN ||
transferType === TransferTypes.RECURRENT_TRANSFER ||
transferType === TransferTypes.TRANSFER_TO_SAVINGS ||
transferType === TransferTypes.TRANSFER_ENGINE ||
transferType === TransferTypes.TRANSFER_SPK ||
Expand Down
4 changes: 4 additions & 0 deletions src/config/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"claim_reward_balance": "Claim Reward ",
"points_activity":"Activity",
"transfer": "Transfer",
"recurrent_transfer": "Recurrent Transfer",
"power_up": "To Vesting",
"transfer_from_savings": "From Savings",
"withdraw_savings":"Withdraw Savings",
Expand Down Expand Up @@ -770,13 +771,16 @@
"to": "To",
"amount_information": "Drag the slider to adjust the amount",
"amount": "Amount",
"recurrence": "Recurrence",
"memo": "Memo",
"recurrent_transfer": "Recurrent Transfer",
"information": "Continue transaction?",
"amount_desc": "Balance",
"memo_desc": "This memo is public",
"convert_desc": "Convert takes 3.5 days and NOT recommended IF HBD price is higher than $1",
"to_placeholder": "Username",
"memo_placeholder": "Enter your notes here",
"recurrence_placeholder": "Recurrence for Months",
"transfer_token": "Transfer",
"purchase_estm": "Purchase Points",
"convert": "Convert HBD to HIVE",
Expand Down
1 change: 1 addition & 0 deletions src/constants/transferTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const TransferTypes = {
POWER_DOWN: 'power_down',
ADDRESS_VIEW: 'address_view',
DELEGATE_VESTING_SHARES: 'delegate_vesting_shares',
RECURRENT_TRANSFER: 'recurrent_transfer',

// Engine Transfer types
WITHDRAW_VESTING: 'withdraw_vesting',
Expand Down
13 changes: 12 additions & 1 deletion src/containers/transferContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
withdrawVesting,
delegateVestingShares,
setWithdrawVestingRoute,
recurrentTransferToken,
} from '../providers/hive/dhive';
import { toastNotification } from '../redux/actions/uiAction';
import { getUserDataWithUsername } from '../realm/realm';
Expand Down Expand Up @@ -63,6 +64,7 @@ class TransferContainer extends Component {
spkMarkets: [],
initialAmount: props.route.params?.initialAmount,
initialMemo: props.route.params?.initialMemo,
initialRecurrence: props.route.params?.initialRecurrence,
};
}

Expand Down Expand Up @@ -188,7 +190,7 @@ class TransferContainer extends Component {
}, 3000);
};

_transferToAccount = async (from, destination, amount, memo) => {
_transferToAccount = async (from, destination, amount, memo, recurrence = null) => {
const { pinCode, navigation, dispatch, intl, route } = this.props;
let { currentAccount } = this.props;
const { selectedAccount } = this.state;
Expand All @@ -205,6 +207,10 @@ class TransferContainer extends Component {
fundType,
};

if (recurrence) {
data.recurrence = +recurrence;
}

if (countDecimals(Number(data.amount)) < 3) {
data.amount = Number(data.amount).toFixed(3);
}
Expand All @@ -214,6 +220,9 @@ class TransferContainer extends Component {
case 'transfer_token':
func = transferToken;
break;
case TransferTypes.RECURRENT_TRANSFER:
func = recurrentTransferToken;
break;
case 'purchase_estm':
func = transferToken;
break;
Expand Down Expand Up @@ -344,6 +353,7 @@ class TransferContainer extends Component {
spkMarkets,
initialAmount,
initialMemo,
initialRecurrence,
} = this.state;

const transferType = route.params?.transferType ?? '';
Expand Down Expand Up @@ -371,6 +381,7 @@ class TransferContainer extends Component {
setWithdrawVestingRoute: this._setWithdrawVestingRoute,
initialAmount,
initialMemo,
initialRecurrence,
})
);
}
Expand Down
39 changes: 39 additions & 0 deletions src/providers/hive/dhive.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { b64uEnc } from '../../utils/b64';
import bugsnagInstance from '../../config/bugsnag';
import bugsnapInstance from '../../config/bugsnag';
import { makeJsonMetadataReply } from '../../utils/editor';
import TransferTypes from '../../constants/transferTypes';

const hiveuri = require('hive-uri');
global.Buffer = global.Buffer || require('buffer').Buffer;
Expand Down Expand Up @@ -987,6 +988,44 @@ export const transferToken = (currentAccount, pin, data) => {
);
};

export const recurrentTransferToken = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey(
{
activeKey: get(currentAccount, 'local.activeKey'),
},
digitPinCode,
);

if (key) {
const privateKey = PrivateKey.fromString(key);
const args = {
from: get(data, 'from'),
to: get(data, 'destination'),
amount: get(data, 'amount'),
memo: get(data, 'memo'),
recurrence: get(data, 'recurrence'),
};
const opArray = [[TransferTypes.RECURRENT_TRANSFER, args]];

return new Promise((resolve, reject) => {
sendHiveOperations(opArray, privateKey)
.then((result) => {
if (result) {
resolve(result);
}
})
.catch((err) => {
reject(err);
});
});
}

return Promise.reject(
new Error('Check private key permission! Required private active key or above.'),
);
};

export const convert = (currentAccount, pin, data) => {
const digitPinCode = getDigitPinCode(pin);
const key = getAnyPrivateKey(
Expand Down
1 change: 1 addition & 0 deletions src/redux/reducers/walletReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface CoinActivity {
details: string | null;
memo: string;
cancelable: boolean;
recurrence: string;
}

export interface QuoteItem {
Expand Down
1 change: 1 addition & 0 deletions src/screens/assetDetails/screen/assetDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ const AssetDetailsScreen = ({ navigation, route }: AssetDetailsScreenProps) => {
referredUsername: baseActivity.details?.split(' ')[2]?.slice(1), // from @user1 to @user2
initialAmount: `${parseToken(baseActivity.value)}`,
initialMemo: baseActivity.memo,
initialRecurrence: `${parseToken(baseActivity.recurrence)}`,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/screens/transfer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const Transfer = ({ navigation, route }) => (
spkMarkets,
initialAmount,
initialMemo,
initialRecurrence,
}) => {
switch (transferType) {
case 'delegate':
Expand Down Expand Up @@ -98,6 +99,7 @@ const Transfer = ({ navigation, route }) => (
referredUsername={referredUsername || ''}
initialAmount={initialAmount || ''}
initialMemo={initialMemo || ''}
initialRecurrence={initialRecurrence || ''}
/>
);
}
Expand Down
21 changes: 18 additions & 3 deletions src/screens/transfer/screen/transferScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const TransferView = ({
referredUsername,
initialAmount,
initialMemo,
transactionData,
initialRecurrence,
}) => {
const dispatch = useAppDispatch();

Expand Down Expand Up @@ -75,6 +75,8 @@ const TransferView = ({
const [memo, setMemo] = useState(
transferType === 'purchase_estm' ? 'estm-purchase' : initialMemo,
);
const [recurrence, setRecurrence] = useState(`${initialRecurrence}`);

const [isUsernameValid, setIsUsernameValid] = useState(
!!(
transferType === 'purchase_estm' ||
Expand Down Expand Up @@ -105,7 +107,13 @@ const TransferView = ({
if (accountType === AUTH_TYPE.STEEM_CONNECT) {
setHsTransfer(true);
} else {
transferToAccount(from, destination, amount, memo);
transferToAccount(
from,
destination,
amount,
memo,
transferType === TransferTypes.RECURRENT_TRANSFER ? recurrence : null,
);
}
},
300,
Expand Down Expand Up @@ -133,7 +141,11 @@ const TransferView = ({
// )}`;
// } else

if (transferType === TransferTypes.TRANSFER_TO_SAVINGS) {
if (transferType === TransferTypes.RECURRENT_TRANSFER) {
path = `sign/recurrent_transfer?from=${currentAccountName}&to=${destination}&amount=${encodeURIComponent(
`${amount} ${fundType}`,
)}&memo=${encodeURIComponent(memo)}&recurrence=${recurrence}`;
} else if (transferType === TransferTypes.TRANSFER_TO_SAVINGS) {
path = `sign/transfer_to_savings?from=${currentAccountName}&to=${destination}&amount=${encodeURIComponent(
`${amount} ${fundType}`,
)}&memo=${encodeURIComponent(memo)}`;
Expand Down Expand Up @@ -200,6 +212,7 @@ const TransferView = ({
`${amount} ${fundType}`,
)}&memo=${encodeURIComponent(memo)}`;
}
console.log('path is: ', path);
}

const _onNextPress = () => {
Expand Down Expand Up @@ -268,6 +281,8 @@ const TransferView = ({
setMemo={setMemo}
amount={amount}
setAmount={setAmount}
recurrence={recurrence}
setRecurrence={setRecurrence}
hsTransfer={hsTransfer}
transferType={transferType}
selectedAccount={selectedAccount}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ const HIVE_ACTIONS = [
'transfer_to_savings',
'transfer_to_vesting',
'withdraw_hive',
'swap_token'
'swap_token',
TransferTypes.RECURRENT_TRANSFER
];
const HBD_ACTIONS = [
'transfer_token',
Expand Down

0 comments on commit 4c571b5

Please sign in to comment.