Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
creed-victor committed Jan 10, 2024
1 parent 352b96a commit 872da50
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 390 deletions.
11 changes: 10 additions & 1 deletion apps/frontend/src/app/3_organisms/Boltz/Boltz.constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { ChainIds } from '@sovryn/ethers-provider';

export const BOLTZ_URL = {
import { defaultChainId } from '../../../config/chains';

export const BOLTZ_API_URLS = {
[ChainIds.RSK_MAINNET]: 'https://api.boltz.exchange/',
[ChainIds.RSK_TESTNET]: 'https://testnet.boltz.exchange/api/',
};

export const BOLTZ_EXCHANGE_URLS = {
[ChainIds.RSK_MAINNET]: 'https://boltz.exchange/',
[ChainIds.RSK_TESTNET]: 'https://testnet.boltz.exchange/',
};

export const BOLTZ_EXCHANGE_URL = BOLTZ_EXCHANGE_URLS[defaultChainId];
16 changes: 9 additions & 7 deletions apps/frontend/src/app/3_organisms/Boltz/Boltz.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getAddress, parseUnits } from 'ethers/lib/utils';

import { defaultChainId } from '../../../config/chains';

import { BOLTZ_URL } from './Boltz.constants';
import { BOLTZ_API_URLS } from './Boltz.constants';
import {
BoltzPair,
CheckSwapStatusResponse,
Expand All @@ -19,7 +19,9 @@ import {

export const getPair = async () => {
try {
const { data } = await axios.get(BOLTZ_URL[defaultChainId] + 'getpairs');
const { data } = await axios.get(
BOLTZ_API_URLS[defaultChainId] + 'getpairs',
);

return data.pairs['RBTC/BTC'] as BoltzPair;
} catch (error) {}
Expand All @@ -28,7 +30,7 @@ export const getPair = async () => {
export const checkSwapStatus = async (id: string) => {
try {
const { data } = await axios.post<CheckSwapStatusResponse>(
BOLTZ_URL[defaultChainId] + 'swapstatus',
BOLTZ_API_URLS[defaultChainId] + 'swapstatus',
{
id,
},
Expand All @@ -43,7 +45,7 @@ export const streamSwapStatus = async (
cb: (status: any) => void,
) => {
const stream = new EventSource(
BOLTZ_URL[defaultChainId] + '/streamswapstatus?id=' + id,
BOLTZ_API_URLS[defaultChainId] + '/streamswapstatus?id=' + id,
);

stream.onmessage = function (event) {
Expand Down Expand Up @@ -77,7 +79,7 @@ export const swapToBTC = async (
};

const { data } = await axios.post<CreateReverseSwapResponse>(
BOLTZ_URL[defaultChainId] + 'createswap',
BOLTZ_API_URLS[defaultChainId] + 'createswap',
params,
);

Expand Down Expand Up @@ -114,7 +116,7 @@ export const swapToLighting = async (
};

const { data } = await axios.post<CreateSwapResponse>(
BOLTZ_URL[defaultChainId] + 'createswap',
BOLTZ_API_URLS[defaultChainId] + 'createswap',
params,
);

Expand All @@ -134,7 +136,7 @@ export const swapToLighting = async (
export const getContracts = async () => {
try {
const { data } = await axios.get<GetContractsResponse>(
BOLTZ_URL[defaultChainId] + 'getcontracts',
BOLTZ_API_URLS[defaultChainId] + 'getcontracts',
);

return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import {
streamSwapStatus,
swapToLighting,
} from '../../../../Boltz/Boltz.utils';
import EtherSwapABI from '../../../../Boltz/EtherSwap.json';
import { TransactionType } from '../../../../TransactionStepDialog/TransactionStepDialog.types';
import {
WithdrawBoltzContext,
WithdrawBoltzStep,
} from '../../../contexts/withdraw-boltz-context';
import EtherSwapABI from '../../../utils/EtherSwap.json';
import { BoltzStatusType } from './BoltzStatus';
import { StatusScreen } from './StatusScreen';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,38 @@ import { Heading, HeadingType, Link } from '@sovryn/ui';

import { HELPDESK_LINK } from '../../../../../../constants/links';
import { translations } from '../../../../../../locales/i18n';
import { BOLTZ_EXCHANGE_URL } from '../../../../Boltz/Boltz.constants';

export const Instructions: React.FC = () => {
return (
<>
<Heading type={HeadingType.h2} className="font-medium leading-[1.375rem]">
{t(translations.boltz.sendInstructions.title)}:
</Heading>
export const Instructions: React.FC = () => (
<>
<Heading type={HeadingType.h2} className="font-medium leading-[1.375rem]">
{t(translations.boltz.sendInstructions.title)}:
</Heading>

<ul className="list-disc list-inside text-xs leading-5 font-medium text-gray-30 mt-4 mb-12">
<li className="mb-4">
<Trans
i18nKey={t(translations.boltz.sendInstructions.line1)}
components={[
<Link
text={t(translations.boltz.sendInstructions.line1cta)}
href={'https://boltz.exchange'}
/>,
]}
/>
</li>
<li className="mb-4">{t(translations.boltz.sendInstructions.line2)}</li>
<li>
<Trans
i18nKey={t(translations.boltz.sendInstructions.line3)}
components={[
<Link
text={t(translations.boltz.sendInstructions.line3cta)}
href={HELPDESK_LINK}
/>,
]}
/>
</li>
</ul>
</>
);
};
<ul className="list-disc list-inside text-xs leading-5 font-medium text-gray-30 mt-4 mb-12">
<li className="mb-4">
<Trans
i18nKey={t(translations.boltz.sendInstructions.line1)}
components={[
<Link
text={t(translations.boltz.sendInstructions.line1cta)}
href={BOLTZ_EXCHANGE_URL}
/>,
]}
/>
</li>
<li className="mb-4">{t(translations.boltz.sendInstructions.line2)}</li>
<li>
<Trans
i18nKey={t(translations.boltz.sendInstructions.line3)}
components={[
<Link
text={t(translations.boltz.sendInstructions.line3cta)}
href={HELPDESK_LINK}
/>,
]}
/>
</li>
</ul>
</>
);
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,25 @@ export const InvoiceForm: React.FC = () => {

const validateInvoice = useCallback(
(invoice: string) => {
setInvoiceValidationState(InvoiceValidationState.LOADING);
const decoded = decodeInvoice(invoice);
if (decoded) {
if ((decoded.expiry ?? 0) < Date.now() / 1000) {
setInvoiceValidationState(InvoiceValidationState.EXPIRED);
return;
}

if (!decimalic(amount).eq(decimalic(decoded.satoshis).div(1e8))) {
setInvoiceValidationState(InvoiceValidationState.BALANCE);
return;
try {
setInvoiceValidationState(InvoiceValidationState.LOADING);
const decoded = decodeInvoice(invoice);
if (decoded) {
if ((decoded.expiry ?? 0) < Date.now() / 1000) {
setInvoiceValidationState(InvoiceValidationState.EXPIRED);
return;
}

if (!decimalic(amount).eq(decimalic(decoded.satoshis).div(1e8))) {
setInvoiceValidationState(InvoiceValidationState.BALANCE);
return;
}

setInvoiceValidationState(InvoiceValidationState.VALID);
} else {
setInvoiceValidationState(InvoiceValidationState.INVALID);
}

setInvoiceValidationState(InvoiceValidationState.VALID);
} else {
} catch (e) {
setInvoiceValidationState(InvoiceValidationState.INVALID);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from '@sovryn/ui';

import { AmountRenderer } from '../../../../../2_molecules/AmountRenderer/AmountRenderer';
import { StatusIcon } from '../../../../../2_molecules/StatusIcon/StatusIcon';
import { TxIdWithNotification } from '../../../../../2_molecules/TxIdWithNotification/TransactionIdWithNotification';
import { BITCOIN } from '../../../../../../constants/currencies';
import { useMaintenance } from '../../../../../../hooks/useMaintenance';
Expand All @@ -24,69 +23,10 @@ import { getRskExplorerUrl } from '../../../../../../utils/helpers';
import { decimalic } from '../../../../../../utils/math';
import { WithdrawBoltzContext } from '../../../contexts/withdraw-boltz-context';
import { BoltzStatus, BoltzStatusType } from './BoltzStatus';
import { getDescription, getTitle } from './StatusScreen.utils';

const translation = translations.boltz.send.confirmationScreens;

const getTitle = (txStatus: StatusType, BoltzStatus: BoltzStatusType) => {
if (!BoltzStatus) {
return t(translation.titles.default);
}
if (txStatus === StatusType.error) {
return t(translation.titles.error);
}

if (
txStatus === StatusType.success &&
[
BoltzStatusType.paid,
BoltzStatusType.txClaimed,
BoltzStatusType.settled,
].includes(BoltzStatus)
) {
return t(translation.titles.success);
}

return t(translation.titles.pending);
};

const getDescription = (txStatus: StatusType, boltzStatus: BoltzStatusType) => {
if (txStatus === StatusType.idle || !boltzStatus) {
return t(translation.descriptions.default);
}

if (txStatus === StatusType.error) {
return (
<StatusIcon
status={StatusType.error}
dataAttribute="funding-send-status"
/>
);
}

if (
txStatus === StatusType.success &&
[
BoltzStatusType.paid,
BoltzStatusType.txClaimed,
BoltzStatusType.settled,
].includes(boltzStatus)
) {
return (
<StatusIcon
status={StatusType.success}
dataAttribute="funding-send-status"
/>
);
}

return (
<StatusIcon
status={StatusType.pending}
dataAttribute="funding-send-status"
/>
);
};

const rskExplorerUrl = getRskExplorerUrl();

type StatusScreenProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from 'react';

import { t } from 'i18next';

import { StatusType } from '@sovryn/ui';

import { StatusIcon } from '../../../../../2_molecules/StatusIcon/StatusIcon';
import { translations } from '../../../../../../locales/i18n';
import { BoltzStatusType } from './BoltzStatus';

const translation = translations.boltz.send.confirmationScreens;

export const getTitle = (
txStatus: StatusType,
BoltzStatus: BoltzStatusType,
) => {
if (!BoltzStatus) {
return t(translation.titles.default);
}
if (txStatus === StatusType.error) {
return t(translation.titles.error);
}

if (
txStatus === StatusType.success &&
[
BoltzStatusType.paid,
BoltzStatusType.txClaimed,
BoltzStatusType.settled,
].includes(BoltzStatus)
) {
return t(translation.titles.success);
}

return t(translation.titles.pending);
};

export const getDescription = (
txStatus: StatusType,
boltzStatus: BoltzStatusType,
) => {
if (txStatus === StatusType.idle || !boltzStatus) {
return t(translation.descriptions.default);
}

if (txStatus === StatusType.error) {
return (
<StatusIcon
status={StatusType.error}
dataAttribute="funding-send-status"
/>
);
}

if (
txStatus === StatusType.success &&
[
BoltzStatusType.paid,
BoltzStatusType.txClaimed,
BoltzStatusType.settled,
].includes(boltzStatus)
) {
return (
<StatusIcon
status={StatusType.success}
dataAttribute="funding-send-status"
/>
);
}

return (
<StatusIcon
status={StatusType.pending}
dataAttribute="funding-send-status"
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import { Network, useFastBtcDialogStore } from '../../store';
import { BoltzSendFlow } from '../BoltzSendFlow/BoltzSendFlow';
import { ReceiveFlow } from '../ReceiveFlow/ReceiveFlow';
import { SendFlow } from '../SendFlow/SendFlow';

export enum Direction {
Receive,
Send,
}
import { Direction } from './NetworkChooser.type';

type NetworkChooserProps = {
direction: Direction;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum Direction {
Receive,
Send,
}
2 changes: 0 additions & 2 deletions apps/frontend/src/app/3_organisms/FastBtcDialog/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ export const DEPOSIT_FEE_DYNAMIC = 20;
export const DYNAMIC_FEE_DIVISOR = 10000;

export const GAS_LIMIT_FAST_BTC_WITHDRAW = 200000;

export const GAS_LIMIT_BOLTZ_SEND = 200000;
Loading

0 comments on commit 872da50

Please sign in to comment.