Skip to content

Commit

Permalink
fix: transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
lulu-tro committed Oct 21, 2024
1 parent 461a744 commit 92e0bd1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
26 changes: 15 additions & 11 deletions src/components/Modals/TransferConfirmModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ export default function TransferConfirmModal({ color }) {
const intl = useIntl();
const inputAddressRef = useRef(null);
const inputAmountRef = useRef(null);
const tokenRef = useRef('BTT');
// const tokenRef = useRef('BTT');
const maxRef = useRef(null);
const [showModal, setShowModal] = useState(false);
const [showConfirm, setShowConfirm] = useState(false);
const [max, setMax] = useState(0);
const [valid, setValid] = useState(false);
const [tokenCurrent, setTokenCurrent] = useState('BTT');


useEffect(() => {
const set = async function (params) {
console.log('openTransferConfirmModal event has occured');
openModal();
inputAmountRef.current.value = ''
tokenRef.current = 'BTT';
// tokenRef.current = 'BTT';
setTokenCurrent('BTT')
const currentObj = {
BTT: params.maxBTT,
};
Expand Down Expand Up @@ -56,23 +59,23 @@ export default function TransferConfirmModal({ color }) {
setShowConfirm(false);

let result;
if (tokenRef.current === 'BTT') {
if (tokenCurrent === 'BTT') {
result = await BTTTransfer(
inputAddressRef.current.value.trim(),
inputAmountRef.current.value,
tokenRef.current
tokenCurrent
);
}else if (tokenRef.current === 'WBTT') {
}else if (tokenCurrent === 'WBTT') {
result = await WBTTTransfer(
inputAddressRef.current.value.trim(),
inputAmountRef.current.value,
tokenRef.current
tokenCurrent
);
} else {
result = await currencyTransfer(
inputAddressRef.current.value.trim(),
inputAmountRef.current.value,
tokenRef.current
tokenCurrent
);
}

Expand Down Expand Up @@ -118,7 +121,8 @@ export default function TransferConfirmModal({ color }) {
};

const handleChange = useCallback(value => {
tokenRef.current = value;
// tokenRef.current = value;
setTokenCurrent(value)
inputAmountRef.current.value = null;

if (value === 'BTT') {
Expand Down Expand Up @@ -170,7 +174,7 @@ export default function TransferConfirmModal({ color }) {
className={'theme-border-color ' + color}
defaultValue="BTT"
style={{ width: 90 }}
value={tokenRef.current}
value={tokenCurrent}
onChange={handleChange}
// dropdownStyle={{ background: themeStyle.bg[color] }}
>
Expand Down Expand Up @@ -232,7 +236,7 @@ export default function TransferConfirmModal({ color }) {
<div className="flex-1">
<p className="p-2">{t('send_amount')}</p>
<p className="p-2 font-semibold">
{inputAmountRef.current?.value} &nbsp; {tokenRef.current}
{inputAmountRef.current?.value} &nbsp; {tokenCurrent}
</p>
</div>
<div className="flex-1">
Expand All @@ -246,7 +250,7 @@ export default function TransferConfirmModal({ color }) {
<div>
{t('total')}: &nbsp;
<span className="text-xl font-semibold">
{inputAmountRef.current?.value} {tokenRef.current} + {FEE} BTT
{inputAmountRef.current?.value} {tokenCurrent} + {FEE} BTT
</span>
</div>
<div>
Expand Down
15 changes: 9 additions & 6 deletions src/components/Modals/WithdrawDepositModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { Option } = Select;
export default function WithdrawDepositModal({ color }) {
const intl = useIntl();
const inputRef = useRef(null);
const tokenRef = useRef('WBTT');
// const tokenRef = useRef('WBTT');/
const [type, setType] = useState(null);
const [title, setTitle] = useState(null);
const [description, setDescription] = useState(null);
Expand All @@ -25,13 +25,15 @@ export default function WithdrawDepositModal({ color }) {
const [account, setAccount] = useState(null);
const [valid, setValid] = useState(false);
const maxRef = useRef(null);
const [tokenCurrent, setTokenCurrent] = useState('BTT');


useEffect(() => {
const set = function (params) {
openModal();
setType(params.type);
let currentObj = {};
const token = tokenRef.current || 'WBTT';
const token = tokenCurrent || 'WBTT';

if (params.type === 'withdraw') {
setTitle('chequebook_withdraw');
Expand Down Expand Up @@ -92,7 +94,7 @@ export default function WithdrawDepositModal({ color }) {
const _withdraw = async () => {
let amount = inputRef.current.value;
closeModal();
let result = await withdraw(amount, tokenRef.current);
let result = await withdraw(amount, tokenCurrent);
if (result['Type'] === 'error') {
Emitter.emit('showMessageAlert', { message: result['Message'], status: 'error' });
} else {
Expand All @@ -104,7 +106,7 @@ export default function WithdrawDepositModal({ color }) {
const _deposit = async () => {
let amount = inputRef.current.value;
closeModal();
let result = await deposit(amount, tokenRef.current);
let result = await deposit(amount, tokenCurrent);
if (result['Type'] === 'error') {
Emitter.emit('showMessageAlert', { message: result['Message'], status: 'error' });
} else {
Expand Down Expand Up @@ -154,7 +156,8 @@ export default function WithdrawDepositModal({ color }) {
window.body.style.overflow = '';
};
const handleChange = useCallback(value => {
tokenRef.current = value;
// tokenRef.current = value;
setTokenCurrent(value)
inputRef.current.value = null;
if (value === 'BTT') {
setMax(maxRef.current.BTT);
Expand Down Expand Up @@ -187,7 +190,7 @@ export default function WithdrawDepositModal({ color }) {
defaultValue="WBTT"
style={{ width: 100 }}
onChange={handleChange}
value={tokenRef.current}
value={tokenCurrent}
// dropdownStyle={{ background: themeStyle.bg[color] }}
>
{MULTIPLE_CURRENCY_LIST.map(item => {
Expand Down

0 comments on commit 92e0bd1

Please sign in to comment.