Skip to content

Commit fc0d988

Browse files
authored
Merge pull request #92 from bitsnark/feat/FF-89
environment variables configuration
2 parents bc8f7c5 + 49ab992 commit fc0d988

11 files changed

Lines changed: 100 additions & 25 deletions

File tree

.env.sample

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
VITE_WALLETCONNECT_PROJECT_ID=""
22
VITE_RPC_URL=""
3-
VITE_API_BASE_URL=""
4-
VITE_EXPIRATION_HOURS=24
3+
VITE_API_BASE_URL="https://florin.bitcoinos.build"
4+
VITE_EXPIRATION_HOURS=24
5+
VITE_MIN_AMOUNT="0.0004"
6+
VITE_MAX_AMOUT="3"
7+
VITE_EVM_CONFIRMATIONS_LOW=1
8+
VITE_EVM_CONFIRMATIONS_HIGH=10
9+
VITE_EVM_CONFIRMATIONS_USD_AMOUNT=100
10+
VITE_BTC_CONFIRMATIONS=6

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ jobs:
3535
VITE_RPC_URL: ${{ secrets.VITE_RPC_URL }}
3636
VITE_API_BASE_URL: ${{ secrets.VITE_API_BASE_URL }}
3737
VITE_EXPIRATION_HOURS: ${{ secrets.VITE_EXPIRATION_HOURS }}
38+
VITE_MIN_AMOUNT: ${{ secrets.VITE_MIN_AMOUNT }}
39+
VITE_MAX_AMOUNT: ${{ secrets.VITE_MAX_AMOUNT }}
40+
VITE_EVM_CONFIRMATIONS_LOW: ${{ secrets.VITE_EVM_CONFIRMATIONS_LOW }}
41+
VITE_EVM_CONFIRMATIONS_HIGH: ${{ secrets.VITE_EVM_CONFIRMATIONS_HIGH }}
42+
VITE_EVM_CONFIRMATIONS_USD_AMOUNT: ${{ secrets.VITE_EVM_CONFIRMATIONS_USD_AMOUNT }}
43+
VITE_BTC_CONFIRMATIONS: ${{ secrets.VITE_BTC_CONFIRMATIONS }}
3844

3945
- name: Build
4046
run: npm run build
@@ -43,3 +49,9 @@ jobs:
4349
VITE_RPC_URL: ${{ secrets.VITE_RPC_URL }}
4450
VITE_API_BASE_URL: ${{ secrets.VITE_API_BASE_URL }}
4551
VITE_EXPIRATION_HOURS: ${{ secrets.VITE_EXPIRATION_HOURS }}
52+
VITE_MIN_AMOUNT: ${{ secrets.VITE_MIN_AMOUNT }}
53+
VITE_MAX_AMOUNT: ${{ secrets.VITE_MAX_AMOUNT }}
54+
VITE_EVM_CONFIRMATIONS_LOW: ${{ secrets.VITE_EVM_CONFIRMATIONS_LOW }}
55+
VITE_EVM_CONFIRMATIONS_HIGH: ${{ secrets.VITE_EVM_CONFIRMATIONS_HIGH }}
56+
VITE_EVM_CONFIRMATIONS_USD_AMOUNT: ${{ secrets.VITE_EVM_CONFIRMATIONS_USD_AMOUNT }}
57+
VITE_BTC_CONFIRMATIONS: ${{ secrets.VITE_BTC_CONFIRMATIONS }}

.github/workflows/deploy.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ jobs:
3636
VITE_RPC_URL: ${{ secrets.VITE_RPC_URL }}
3737
VITE_API_BASE_URL: ${{ secrets.VITE_API_BASE_URL }}
3838
VITE_EXPIRATION_HOURS: ${{ secrets.VITE_EXPIRATION_HOURS }}
39+
VITE_MIN_AMOUNT: ${{ secrets.VITE_MIN_AMOUNT }}
40+
VITE_MAX_AMOUNT: ${{ secrets.VITE_MAX_AMOUNT }}
41+
VITE_EVM_CONFIRMATIONS_LOW: ${{ secrets.VITE_EVM_CONFIRMATIONS_LOW }}
42+
VITE_EVM_CONFIRMATIONS_HIGH: ${{ secrets.VITE_EVM_CONFIRMATIONS_HIGH }}
43+
VITE_EVM_CONFIRMATIONS_USD_AMOUNT: ${{ secrets.VITE_EVM_CONFIRMATIONS_USD_AMOUNT }}
44+
VITE_BTC_CONFIRMATIONS: ${{ secrets.VITE_BTC_CONFIRMATIONS }}
3945
- name: Deploy to Netlify
4046
run: |
4147
DEPLOY_COMMAND="netlify deploy \

src/components/tabs-switcher/transfer-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export function TransferForm({
145145
>
146146
Bitcoin receiving address
147147
<InfoTooltip
148-
message="Enter the Bitcoin address where you want to receive your BTC."
148+
message="Enter the P2WPKH Bitcoin address where you want to receive your BTC."
149149
position="top"
150150
/>
151151
</Label>

src/components/transaction-tracker/btc-completion-card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function BtcCompletionCard({
1616
amount,
1717
recipientAddress,
1818
reservationTx,
19-
confirmations = 20,
19+
confirmations = 1,
2020
type = 'position',
2121
}: BtcCompletionCardProps) {
2222
const logoSrc = type === 'position' ? bitcoinLogo : ethLogo;

src/components/transaction-tracker/btc-transaction-card.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import BtcLogo from '@/assets/bitcoin-logo.png';
66
import { CheckCircledIcon } from '@radix-ui/react-icons';
77
import { getExplorerUrl, truncateAddress } from '@/lib/utils';
88
import { InfoField } from './info-field';
9+
import { env } from '@/config/env';
910

1011
export interface BtcTransactionCardProps {
1112
data: {
@@ -22,7 +23,7 @@ export interface BtcTransactionCardProps {
2223

2324
const isHighAmount = (amount: string) => {
2425
const amountNumber = parseFloat(amount);
25-
return amountNumber >= 100;
26+
return amountNumber >= env.VITE_EVM_CONFIRMATIONS_USD_AMOUNT;
2627
};
2728

2829
export function BtcTransactionCard({
@@ -47,7 +48,7 @@ export function BtcTransactionCard({
4748
return (
4849
<div className="flex items-center justify-center gap-1">
4950
<span className="text-white text-[12px] font-medium">
50-
{data.confirmations}
51+
{Math.min(Number(data?.confirmations) || 0, Number(data.maxConfirmations) || 0)}
5152
</span>
5253
<CheckCircledIcon className="text-green-600 w-4 h-4" />
5354
</div>
@@ -108,7 +109,7 @@ export function BtcTransactionCard({
108109
label="Confirmations"
109110
value={
110111
<span className="text-white text-[12px] font-medium">
111-
{data.confirmations}
112+
{renderConfirmations()}
112113
</span>
113114
}
114115
/>

src/components/transaction-tracker/position-tracker.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { useMemo } from 'react';
1111
import { useBitcoinPrice } from '@/hooks/useBitcoinPrice';
1212
import { PositionStatus } from '@/types';
1313
import { POSITION_STATUS_MAP } from '../history-table/transaction-history-adapter';
14+
import { env } from '@/config/env';
15+
import { useBtcBlockConfirmations } from '@/hooks/useBtcBlockConfirmations';
1416

1517
interface PositionTrackerProps {
1618
open: boolean;
@@ -41,18 +43,31 @@ export function PositionTracker({
4143
return usdValue.toFixed(2);
4244
}, [evmPosition?.originalAmount, bitcoinPrice?.bitcoin?.usd]);
4345

44-
const maxConfirmations = Number(fiatAmount) > 1000 ? 20 : 6;
46+
const maxConfirmations =
47+
Number(fiatAmount) > env.VITE_EVM_CONFIRMATIONS_USD_AMOUNT
48+
? env.VITE_EVM_CONFIRMATIONS_HIGH
49+
: env.VITE_EVM_CONFIRMATIONS_LOW;
4550
const confirmations = useTxConfirmations({
4651
isActive: open,
4752
maxConfirmations: maxConfirmations,
4853
transactionHash: txHash,
4954
});
55+
5056
const status = POSITION_STATUS_MAP[evmPosition?.status || 1];
5157
const isPositionCompleted = status === PositionStatus.Closed;
5258
const displayConfirmations = isPositionCompleted
5359
? maxConfirmations
5460
: confirmations;
5561

62+
const targetConfirmations = useBtcBlockConfirmations({
63+
isActive: isPositionCompleted,
64+
blockNumber: position?.targetBlockNumber,
65+
});
66+
67+
const displayTargetConfirmations = isPositionCompleted
68+
? env.VITE_BTC_CONFIRMATIONS
69+
: targetConfirmations;
70+
5671
return (
5772
<BaseTransactionTracker
5873
open={open}
@@ -92,9 +107,12 @@ export function PositionTracker({
92107
>
93108
{isPositionCompleted && (
94109
<BtcCompletionCard
110+
confirmations={displayTargetConfirmations}
95111
amount={amount}
96112
recipientAddress={evmPosition?.positionId || ''}
97-
reservationTx={position?.targetTxhash || position?.targetBlockHash || ''}
113+
reservationTx={
114+
position?.targetTxhash || position?.targetBlockHash || ''
115+
}
98116
type="position"
99117
/>
100118
)}

src/components/transaction-tracker/reservation-tracker.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Address, formatUnits } from 'viem';
1313
import { useReservation } from '@/hooks/queries/useReservation';
1414
import { RESERVATION_STATUS_MAP } from '../history-table/transaction-history-adapter';
1515
import { useBtcBlockConfirmations } from '@/hooks/useBtcBlockConfirmations';
16+
import { env } from '@/config/env';
1617

1718
interface ReservationTrackerProps {
1819
open: boolean;
@@ -36,7 +37,7 @@ export function ReservationTracker({
3637

3738
const {
3839
evmReservation,
39-
// isLoading: isEVMReservationLoading,
40+
// isLoading: isEVMReservationLoading,
4041
error: isEVMReservationError,
4142
} = useEVMReservationPolling({
4243
reservationId: id || '',
@@ -52,8 +53,10 @@ export function ReservationTracker({
5253
return usdValue.toFixed(2);
5354
}, [amount, bitcoinPrice?.bitcoin?.usd]);
5455

55-
56-
const maxConfirmations = Number(fiatAmount) > 1000 ? 20 : 6;
56+
const maxConfirmations =
57+
Number(fiatAmount) > env.VITE_EVM_CONFIRMATIONS_USD_AMOUNT
58+
? env.VITE_EVM_CONFIRMATIONS_HIGH
59+
: env.VITE_EVM_CONFIRMATIONS_LOW;
5760
const confirmations = useTxConfirmations({
5861
isActive: open,
5962
maxConfirmations: maxConfirmations,
@@ -151,7 +154,7 @@ export function ReservationTracker({
151154
txid: reservation?.originTxhash,
152155
confirmations: btcConfirmations,
153156
fiatAmount: fiatAmount,
154-
maxConfirmations: maxConfirmations,
157+
maxConfirmations: env.VITE_BTC_CONFIRMATIONS,
155158
}}
156159
isStepThree={true}
157160
/>

src/config/env.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ const envSchema = z.object({
1414
.refine((val) => val > 0, {
1515
message: 'VITE_EXPIRATION_HOURS must be greater than 0',
1616
}),
17+
VITE_MIN_AMOUNT: z.string().transform((val) => Number(val)).refine((val) => val > 0, {
18+
message: 'VITE_MIN_AMOUNT must be greater than 0',
19+
}),
20+
VITE_MAX_AMOUNT: z.string().transform((val) => Number(val)).refine((val) => val > 0, {
21+
message: 'VITE_MAX_AMOUNT must be greater than 0',
22+
}),
23+
VITE_EVM_CONFIRMATIONS_LOW: z.string().transform((val) => Number(val)).refine((val) => val > 0, {
24+
message: 'VITE_EVM_CONFIRMATIONS_LOW must be greater than 0',
25+
}),
26+
VITE_EVM_CONFIRMATIONS_HIGH: z.string().transform((val) => Number(val)).refine((val) => val > 0, {
27+
message: 'VITE_EVM_CONFIRMATIONS_HIGH must be greater than 0',
28+
}),
29+
VITE_EVM_CONFIRMATIONS_USD_AMOUNT: z.string().transform((val) => Number(val)).refine((val) => val > 0, {
30+
message: 'VITE_EVM_CONFIRMATIONS_USD_AMOUNT must be greater than 0',
31+
}),
32+
VITE_BTC_CONFIRMATIONS: z.string().transform((val) => Number(val)).refine((val) => val > 0, {
33+
message: 'VITE_BTC_CONFIRMATIONS must be greater than 0',
34+
})
1735
});
1836

1937
const parsed = envSchema.safeParse(import.meta.env);

src/services/Api.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,9 @@ export class FlorinApiService {
9797
maxAmount: number;
9898
minAmount: number;
9999
}> {
100-
//const response = await fetch(`${API_BASE_URL}/positions/max-min-amount`);
101-
/* if (!response.ok) {
102-
throw new Error(`Failed to fetch max amount: ${response.statusText}`);
103-
} */
104-
// const data = await response.json();
105-
106100
return {
107-
maxAmount: 3,
108-
minAmount: 0.0004,
101+
maxAmount: env.VITE_MAX_AMOUNT,
102+
minAmount: env.VITE_MIN_AMOUNT,
109103
};
110104
}
111105

0 commit comments

Comments
 (0)