Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement stablesats for galoy connector #2730 #3020

Merged
merged 10 commits into from
Mar 14, 2024
9 changes: 7 additions & 2 deletions src/app/components/TransactionsTable/TransactionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function TransactionModal({
keyPrefix: "transactions_table",
});
const [showMoreFields, setShowMoreFields] = useState(false);
const { getFormattedSats } = useSettings();
const { getFormattedSats, getFormattedInCurrency } = useSettings();

function toggleShowMoreFields() {
setShowMoreFields(!showMoreFields);
Expand Down Expand Up @@ -82,7 +82,12 @@ export default function TransactionModal({
)}
>
{transaction.type == "sent" ? "-" : "+"}{" "}
{getFormattedSats(transaction.totalAmount)}
{!transaction.displayAmount
? getFormattedSats(transaction.totalAmount)
: getFormattedInCurrency(
transaction.displayAmount[0],
transaction.displayAmount[1]
)}
</p>

{!!transaction.totalAmountFiat && (
Expand Down
9 changes: 7 additions & 2 deletions src/app/components/TransactionsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function TransactionsTable({
noResultMsg,
loading = false,
}: Props) {
const { getFormattedSats } = useSettings();
const { getFormattedSats, getFormattedInCurrency } = useSettings();
const [modalOpen, setModalOpen] = useState(false);
const [transaction, setTransaction] = useState<Transaction | undefined>();
const { t } = useTranslation("components", {
Expand Down Expand Up @@ -93,7 +93,12 @@ export default function TransactionsTable({
)}
>
{type == "outgoing" ? "-" : "+"}{" "}
{getFormattedSats(tx.totalAmount)}
{!tx.displayAmount
? getFormattedSats(tx.totalAmount)
: getFormattedInCurrency(
tx.displayAmount[0],
tx.displayAmount[1]
)}
</p>

{!!tx.totalAmountFiat && (
Expand Down
5 changes: 5 additions & 0 deletions src/app/hooks/useTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export const useTransactions = () => {
);

for (const transaction of transactions) {
if (
transaction.displayAmount &&
transaction.displayAmount[1] === settings.currency
)
continue;
transaction.totalAmountFiat = settings.showFiat
? await getFormattedFiat(transaction.totalAmount)
: "";
Expand Down
6 changes: 6 additions & 0 deletions src/app/screens/Home/AllowanceView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const AllowanceView: FC<Props> = (props) => {
try {
// attach fiatAmount if enabled
for (const transaction of transactions) {
if (
reneaaron marked this conversation as resolved.
Show resolved Hide resolved
transaction.displayAmount &&
transaction.displayAmount[1] === settings.currency
)
continue;
transaction.totalAmountFiat = showFiat
? await getFormattedFiat(transaction.totalAmount)
: "";
Expand All @@ -74,6 +79,7 @@ const AllowanceView: FC<Props> = (props) => {
transactions,
getFormattedFiat,
showFiat,
settings.currency,
]);

const hasBudget = +props.allowance.totalBudget > 0;
Expand Down
7 changes: 6 additions & 1 deletion src/app/screens/Publishers/Detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ function PublisherDetail() {
);

for (const payment of _transactions) {
if (
payment.displayAmount &&
payment.displayAmount[1] === settings.currency
)
continue;
payment.totalAmountFiat = settings.showFiat
? await getFormattedFiat(payment.totalAmount)
: "";
Expand All @@ -53,7 +58,7 @@ function PublisherDetail() {
console.error(e);
if (e instanceof Error) toast.error(`Error: ${e.message}`);
}
}, [id, settings.showFiat, getFormattedFiat]);
}, [id, settings.showFiat, getFormattedFiat, settings.currency]);

useEffect(() => {
// Run once.
Expand Down
37 changes: 34 additions & 3 deletions src/app/screens/connectors/ConnectGaloy/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ConnectorForm from "@components/ConnectorForm";
import Input from "@components/form/Input";
import Select from "@components/form/Select";
import ConnectionErrorToast from "@components/toasts/ConnectionErrorToast";
import fetchAdapter from "@vespaiach/axios-fetch-adapter";
import axios from "axios";
Expand Down Expand Up @@ -54,11 +55,16 @@ export default function ConnectGaloy(props: Props) {
});
const [loading, setLoading] = useState(false);
const [authToken, setAuthToken] = useState<string | undefined>();
const [currency, setCurrency] = useState<string>("BTC");

function handleAuthTokenChange(event: React.ChangeEvent<HTMLInputElement>) {
setAuthToken(event.target.value.trim());
}

function handleCurrencyChange(event: React.ChangeEvent<HTMLSelectElement>) {
setCurrency(event.target.value);
}

async function loginWithAuthToken(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
setLoading(true);
Expand Down Expand Up @@ -100,10 +106,10 @@ export default function ConnectGaloy(props: Props) {
} else {
// Find the BTC wallet and get its ID
const btcWallet = meData.data.me.defaultAccount.wallets.find(
(w: Wallet) => w.walletCurrency === "BTC"
(w: Wallet) => w.walletCurrency === currency
);
const walletId = btcWallet.id;
saveAccount({ headers, walletId });
saveAccount({ headers, walletId, currency });
}
} catch (e: unknown) {
console.error(e);
Expand All @@ -122,7 +128,11 @@ export default function ConnectGaloy(props: Props) {
}
}

async function saveAccount(config: { headers: Headers; walletId: string }) {
async function saveAccount(config: {
headers: Headers;
walletId: string;
currency: string;
}) {
setLoading(true);

const account = {
Expand All @@ -132,6 +142,7 @@ export default function ConnectGaloy(props: Props) {
headers: config.headers,
walletId: config.walletId,
apiCompatibilityMode,
currency: config.currency,
},
connector: "galoy",
};
Expand Down Expand Up @@ -215,6 +226,26 @@ export default function ConnectGaloy(props: Props) {
</div>
</div>
}

<div className="mt-6">
<label
htmlFor="currency"
className="block font-medium text-gray-800 dark:text-white"
>
{t(`${i18nPrefix}.currency.label`)}
</label>
<div className="mt-1">
<Select
id="currency"
name="currency"
required
onChange={handleCurrencyChange}
>
<option value="BTC">BTC</option>
<option value="USD">USD (Stablesats)</option>
</Select>
</div>
</div>
</ConnectorForm>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface ConnectorTransaction {
settled: boolean;
settleDate: number;
totalAmount: number;
displayAmount?: [number, ACCOUNT_CURRENCIES];
type: "received" | "sent";
}

Expand Down
Loading
Loading