Skip to content

Commit 550d723

Browse files
Copilot0xrinegade
andcommitted
Replace all mock/demo data with real on-chain blockchain queries and add user statistics
Co-authored-by: 0xrinegade <[email protected]>
1 parent 6634dec commit 550d723

File tree

8 files changed

+2841
-4312
lines changed

8 files changed

+2841
-4312
lines changed

package-lock.json

Lines changed: 1509 additions & 4026 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/OfferCreation.js

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ import { useActionDebounce, useInputValidation } from '../hooks/useActionDebounc
1616
import { validateSolAmount, validateFiatAmount, validateMarketRate } from '../utils/validation';
1717
import { createLogger } from '../utils/logger';
1818
import {
19-
MOCK_SOL_PRICES,
2019
SUPPORTED_CURRENCIES,
2120
SUPPORTED_PAYMENT_METHODS,
22-
VALIDATION_CONSTRAINTS,
23-
DEMO_MODE
21+
VALIDATION_CONSTRAINTS
2422
} from '../constants/tradingConstants';
23+
import { useRealPriceData, useCalculateFiatAmount } from '../hooks/usePriceData';
2524
import ConnectWalletPrompt from './ConnectWalletPrompt';
26-
import DemoIndicator from './DemoIndicator';
2725

2826
const logger = createLogger('OfferCreation');
2927

@@ -42,6 +40,10 @@ const OfferCreation = ({ onStartGuidedWorkflow }) => {
4240
const [txStatus, setTxStatus] = useState(null);
4341
const [showConfirmation, setShowConfirmation] = useState(false);
4442

43+
// Get real price data
44+
const { prices, loading: pricesLoading, error: pricesError, lastUpdated } = useRealPriceData();
45+
const { fiatAmount: calculatedFiatAmount, isValid: priceCalculationValid } = useCalculateFiatAmount(solAmount, fiatCurrency);
46+
4547
// Validation states
4648
const solValidation = useInputValidation(solAmount, validateSolAmount);
4749
const fiatValidation = useInputValidation(fiatAmount, (value) => validateFiatAmount(value, fiatCurrency));
@@ -188,23 +190,25 @@ const OfferCreation = ({ onStartGuidedWorkflow }) => {
188190
}
189191
}
190192

191-
// Calculate fiat amount based on SOL amount (simple conversion for demo)
193+
// Calculate fiat amount based on SOL amount using real prices
192194
const handleSolAmountChange = (e) => {
193195
const sol = e.target.value;
194196
setSolAmount(sol);
195197

196-
if (sol && !isNaN(sol)) {
197-
const calculatedFiat = (parseFloat(sol) * MOCK_SOL_PRICES[fiatCurrency]).toFixed(2);
198+
if (sol && !isNaN(sol) && prices && prices[fiatCurrency]) {
199+
const calculatedFiat = (parseFloat(sol) * prices[fiatCurrency]).toFixed(2);
198200
setFiatAmount(calculatedFiat);
201+
} else if (!sol) {
202+
setFiatAmount('');
199203
}
200204
};
201205

202-
// Update fiat amount when currency changes
206+
// Update fiat amount when currency changes using real prices
203207
const handleCurrencyChange = (e) => {
204208
setFiatCurrency(e.target.value);
205-
if (solAmount && !isNaN(solAmount)) {
209+
if (solAmount && !isNaN(solAmount) && prices && prices[e.target.value]) {
206210
// Recalculate fiat amount with new currency
207-
const calculatedFiat = (parseFloat(solAmount) * MOCK_SOL_PRICES[e.target.value]).toFixed(2);
211+
const calculatedFiat = (parseFloat(solAmount) * prices[e.target.value]).toFixed(2);
208212
setFiatAmount(calculatedFiat);
209213
}
210214
};
@@ -236,17 +240,33 @@ const OfferCreation = ({ onStartGuidedWorkflow }) => {
236240
</div>
237241

238242
{/* Demo mode banner for non-connected users */}
239-
{!wallet.connected && DEMO_MODE.enabled && (
240-
<DemoIndicator
241-
type="banner"
242-
message="Connect Wallet to Create Real Offers"
243-
tooltip={DEMO_MODE.educationalMessages.createOffer}
244-
className="demo-banner-main"
245-
/>
243+
{!wallet.connected && (
244+
<div className="wallet-connection-prompt">
245+
<ConnectWalletPrompt
246+
action="create real offers and trade on the blockchain"
247+
showAsMessage={true}
248+
/>
249+
</div>
246250
)}
247251

248252
<p>Create an offer to sell SOL for fiat currency</p>
249253

254+
{/* Price data status */}
255+
{pricesError && (
256+
<div className="warning-message">
257+
Warning: Unable to fetch current market prices. Please verify amounts manually.
258+
</div>
259+
)}
260+
261+
{prices && lastUpdated && (
262+
<div className="price-info">
263+
Current SOL price: {prices[fiatCurrency]?.toFixed(2)} {fiatCurrency}
264+
<span className="price-updated">
265+
(Updated: {lastUpdated.toLocaleTimeString()})
266+
</span>
267+
</div>
268+
)}
269+
250270
{error && <div className="error-message">{error}</div>}
251271
{success && <div className="success-message">{success}</div>}
252272

@@ -398,7 +418,7 @@ const OfferCreation = ({ onStartGuidedWorkflow }) => {
398418

399419
<div className="network-info">
400420
<p>Network: {network.name}</p>
401-
<p>Current SOL price is estimated based on market rates.</p>
421+
<p>Prices are fetched from live market data sources.</p>
402422
<p>Your SOL will be held in escrow until the trade is completed.</p>
403423
</div>
404424

@@ -466,6 +486,36 @@ const OfferCreation = ({ onStartGuidedWorkflow }) => {
466486
font-size: 0.875rem;
467487
margin-top: 0.25rem;
468488
}
489+
490+
.price-info {
491+
background: var(--color-background-alt);
492+
border: 1px solid var(--color-border);
493+
border-radius: 4px;
494+
padding: 12px;
495+
margin: 1rem 0;
496+
font-size: 0.9rem;
497+
color: var(--color-foreground-muted);
498+
}
499+
500+
.price-updated {
501+
margin-left: 10px;
502+
font-size: 0.8rem;
503+
opacity: 0.7;
504+
}
505+
506+
.warning-message {
507+
background: #fef3c7;
508+
border: 1px solid #f59e0b;
509+
color: #92400e;
510+
padding: 12px;
511+
border-radius: 4px;
512+
margin: 1rem 0;
513+
font-size: 0.9rem;
514+
}
515+
516+
.wallet-connection-prompt {
517+
margin: 1rem 0;
518+
}
469519
`}</style>
470520
</div>
471521
);

0 commit comments

Comments
 (0)