Skip to content

Commit

Permalink
add calculator and menu
Browse files Browse the repository at this point in the history
  • Loading branch information
svrgnty committed Aug 31, 2024
1 parent f52ee31 commit 2996e20
Show file tree
Hide file tree
Showing 12 changed files with 390 additions and 30 deletions.
10 changes: 5 additions & 5 deletions src/components/layout/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ const Footer = () => (
<p>This website provides general information and is not intended as financial or investment advice. Use at your own risk, without warranty, and without reliance on svrgnty.com for losses, injuries, or damages resulting from its use.</p>
</div>
<div className="footer-info">
<p>Est. <FontAwesomeIcon icon={solid('dice-d6')} /><span className="element-invisible">Block</span> 488383</p>
<p>Est. <FontAwesomeIcon icon={solid('dice-d6')} /><span className="element-invisible">Block</span> <a href="https://mempool.space/block/00000000000000000066fd45e09a6bae691b1d9bea1d2b1ccdc7b7adbf89f3a3" target="_blank">488383</a></p>
</div>
<div className="footer-social">
<Link to="/privacy-policy/" className="footer-site">
Privacy policy
</Link>
<ul>
<li><a href="https://getalby.com/p/svrgnty"><FontAwesomeIcon icon={solid('bolt')} /> <span className="element-invisible">Send some sats with lightning</span></a></li>
<li><a href="https://github.com/svrgnty/svrgnty.com"><FontAwesomeIcon icon={brands('github')} /> <span className="element-invisible">Github</span></a></li>
<li><a href="https://snort.social/p/npub17wmr8scqqlp0hmdm6q5v96tnqejsfs238zez6hpy794xtudfpmzqf7kms8"><FontAwesomeIcon icon={solid('feather-pointed')} /> <span className="element-invisible">Nostr</span></a></li>
<li><a href="https://x.com/svrgnty"><FontAwesomeIcon icon={brands('x-twitter')} /> <span className="element-invisible">X</span></a></li>
<li><a href="https://getalby.com/p/svrgnty" target="_blank"><FontAwesomeIcon icon={solid('bolt')} /> <span className="element-invisible">Send some sats with lightning</span></a></li>
<li><a href="https://github.com/svrgnty/svrgnty.com" target="_blank"><FontAwesomeIcon icon={brands('github')} /> <span className="element-invisible">Github</span></a></li>
<li><a href="https://snort.social/p/npub17wmr8scqqlp0hmdm6q5v96tnqejsfs238zez6hpy794xtudfpmzqf7kms8" target="_blank"><FontAwesomeIcon icon={solid('feather-pointed')} /> <span className="element-invisible">Nostr</span></a></li>
<li><a href="https://x.com/svrgnty" target="_blank"><FontAwesomeIcon icon={brands('x-twitter')} /> <span className="element-invisible">X</span></a></li>
</ul>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/components/layout/header.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Link } from "gatsby";

import Share from '../share';
import MainMenu from '../menu';
import logo from '../../../static/images/logo.png';

const Header = () => (
Expand All @@ -11,9 +11,9 @@ const Header = () => (
<Link to="/" className="header-logo">
<img alt="" src={logo} /> svrgnty.com
</Link>
{/* <div className="share">
<Share />
</div> */}
<div className="menu">
<MainMenu />
</div>
</div>
</header>

Expand Down
27 changes: 27 additions & 0 deletions src/components/menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import { slide as Menu } from 'react-burger-menu';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { solid} from '@fortawesome/fontawesome-svg-core/import.macro';
import { Link } from "gatsby"


class MainMenu extends React.Component {
showSettings (event) {
event.preventDefault();
}

render () {
return (
<Menu right customBurgerIcon={ <FontAwesomeIcon icon={solid('bars')} mask={solid('square')} transform="shrink-8" /> } customCrossIcon={ <FontAwesomeIcon icon={solid('times')} /> } disableAutoFocus>
<Link to="/" className="menu-link">
Bitcoin Resources
</Link>
<Link to="/tools/satoshis-converter" className="menu-link">
SATS Converter
</Link>
</Menu>
);
}
}

export default MainMenu;
172 changes: 172 additions & 0 deletions src/components/satconverter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import React, { useState, useEffect, useRef } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { brands, solid } from '@fortawesome/fontawesome-svg-core/import.macro';

const SatConverter = () => {
const [sats, setSats] = useState('');
const [btc, setBtc] = useState('');
const [fiat, setFiat] = useState('');
const [btcFiatRate, setBtcFiatRate] = useState(null);
const [fiatCurrency, setFiatCurrency] = useState('USD');
const selectRef = useRef(null);

const currencyPairs = {
USD: 'XBTUSD',
EUR: 'XBTEUR',
CHF: 'XBTCHF',
};

useEffect(() => {
const fetchBtcFiatRate = async () => {
const response = await fetch(
`https://api.kraken.com/0/public/Ticker?pair=${currencyPairs[fiatCurrency]}`
);
const data = await response.json();
const pair = Object.keys(data.result)[0];
const rate = parseFloat(data.result[pair].c[0]);
setBtcFiatRate(rate);

// Recalculate FIAT value based on the new rate
if (btc) {
const plainBtcValue = btc.replace(/,/g, '');
setFiat(formatWithCommas((parseFloat(plainBtcValue) * rate).toFixed(2)));
}
};
fetchBtcFiatRate();
}, [fiatCurrency]);

const formatWithCommas = (number) => {
const parts = number.split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
};

const handleSatsChange = (e) => {
const satValue = e.target.value.replace(/[^0-9]/g, '');
setSats(formatWithCommas(satValue));
if (satValue) {
const btcValue = (satValue / 100_000_000).toFixed(8);
setBtc(formatWithCommas(btcValue));
setFiat(formatWithCommas((btcValue * btcFiatRate).toFixed(2)));
} else {
setBtc('');
setFiat('');
}
};

const handleBtcChange = (e) => {
const btcValue = e.target.value.replace(/[^0-9.]/g, '');
const plainBtcValue = btcValue.replace(/,/g, ''); // Remove commas for calculations

const formattedBtcValue = btcValue.split('.').length > 1
? `${formatWithCommas(btcValue.split('.')[0])}.${btcValue.split('.')[1].slice(0, 8)}`
: formatWithCommas(btcValue);

setBtc(formattedBtcValue);
if (plainBtcValue) {
const satValue = Math.floor(plainBtcValue * 100_000_000).toString();
setSats(formatWithCommas(satValue));
setFiat(formatWithCommas((parseFloat(plainBtcValue) * btcFiatRate).toFixed(2)));
} else {
setSats('');
setFiat('');
}
};

const handleFiatChange = (e) => {
const fiatValue = e.target.value.replace(/[^0-9.]/g, '');
setFiat(fiatValue);

if (fiatValue && btcFiatRate) {
const btcValue = (parseFloat(fiatValue) / btcFiatRate).toFixed(8);
setBtc(formatWithCommas(btcValue));
setSats(formatWithCommas(Math.floor(btcValue * 100_000_000).toString()));
} else {
setBtc('');
setSats('');
}
};

const handleFiatBlur = () => {
if (fiat) {
setFiat(formatWithCommas(parseFloat(fiat).toFixed(2)));
}
};

const handleFiatCurrencyChange = (e) => {
setFiatCurrency(e.target.value);
// Recalculate FIAT value based on the current BTC value and new exchange rate
if (btc) {
const plainBtcValue = btc.replace(/,/g, '');
setFiat(formatWithCommas((parseFloat(plainBtcValue) * btcFiatRate).toFixed(2)));
}
};

return (
<div className="form-group">
<div className="input-container">
<input
type="text"
id="sats"
placeholder="Enter satoshis amount"
value={sats}
onChange={handleSatsChange}
disabled={!btcFiatRate}
/>
<div className="input-icon sats">
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<g strokeWidth="0"></g>
<g strokeLinecap="round" strokeLinejoin="round"></g>
<g>
<path fillRule="evenodd" clipRule="evenodd" d="M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12ZM8.69253 8.74209L16.3304 10.8053L16.6668 9.34348L9.02893 7.2803L8.69253 8.74209ZM14.2194 5.69235L13.8127 7.46639L12.3649 7.07388L12.7717 5.29984L14.2194 5.69235ZM11.2272 18.7L11.6352 16.9263L10.1872 16.535L9.77913 18.3087L11.2272 18.7ZM15.6482 13.7661L8.01124 11.6995L8.34708 10.2376L15.984 12.3042L15.6482 13.7661ZM7.33193 14.6559L14.9696 16.7197L15.3059 15.2579L7.66823 13.1941L7.33193 14.6559Z" fill="#000000"></path>
</g>
</svg>
SATS
</div>
</div>
<div className="input-container">
<input
type="text"
id="btc"
placeholder="Enter bitcoin amount"
value={btc}
onChange={handleBtcChange}
disabled={!btcFiatRate}
/>
<div className="input-icon btc">
<FontAwesomeIcon icon={brands('bitcoin')} />
BTC
</div>
</div>
<div className="input-container">
<input
type="text"
id="fiat"
placeholder="Enter FIAT amount"
value={fiat}
onChange={handleFiatChange}
onBlur={handleFiatBlur}
disabled={!btcFiatRate}
/>
<div className="input-icon usd">
<FontAwesomeIcon icon={solid('dollar-sign')} />
{fiatCurrency}
</div>
</div>
<div className="input-container">
<select
id="fiatCurrency"
value={fiatCurrency}
onChange={handleFiatCurrencyChange}
ref={selectRef}
>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="CHF">CHF</option>
</select>
</div>
</div>
);
};

export default SatConverter;
67 changes: 67 additions & 0 deletions src/layouts/styles/base/_formfields.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.form-group {
display: flex;
flex-direction: column;
gap: 20px;
max-width: 400px;
margin: 20px auto;

.input-container {
position: relative;
display: flex;
align-items: center;
border: 3px solid #e6e6e6;
border-radius: 10px;
padding: 10px 15px;
background-color: #fff;
//box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.05);

input, select {
flex: 1;
border: none;
outline: none;
font-size: 1.2rem;
background: transparent;
padding-right: 50px;

&::placeholder {
color: #b0b0b0;
}
}

.input-icon {
position: absolute;
right: 15px;
display: flex;
align-items: center;
font-size: 1.2rem;
color: $light-font-color;

&.btc {
color: $gold;
}

&.usd {
color: $pill-green;
}

&.sats {
color: $light-font-color;

svg {
width: 25px;
height: 25px;
margin-right: 0;
}
}

svg {
margin-right: 5px;
}
}

/* Special styles for the select dropdown */
select {
cursor: pointer;
}
}
}
2 changes: 1 addition & 1 deletion src/layouts/styles/components/_hero.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


.hero {
padding: space(10) 0 space(4);
padding: space(12) 0 space(4);
background: url('../../../static/images/space-banner.jpg') #0a0501 center no-repeat;
text-align: center;
color: $white;
Expand Down
27 changes: 14 additions & 13 deletions src/layouts/styles/components/_menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
.bm-cross-button {
height: 1.2em !important;
width: 1.2em !important;
margin: 1em 1em 0 0;
color: $dark-font-color;
}

.bm-menu-wrap {
Expand All @@ -19,29 +21,28 @@

/* General sidebar styles */
.bm-menu {
background: $primary-dark;
background: $card-bg;
padding: 2.5em 1.5em;
font-size: 1.15em;
font-size: 1em;
font-weight: $extra-bold-weight;

svg {
width: 1.2em !important;
text-align: center;
}
}

/* Wrapper for item list */
.bm-item-list {
padding: 0.8em;
.menu-link {
padding: 0.5em 0 0.5em 0;
border-bottom: 1px solid $gold;
}

.bm-overlay {
background: none !important;
top: 0;
left: 0;
}

.share-link,
.bm-cross-button {
&:active,
&:hover {
color: $gold !important;
}
}
/* Wrapper for item list */
.bm-item-list {
padding: 0.8em;
}
Loading

0 comments on commit 2996e20

Please sign in to comment.