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

Fiat balance example and cleanup #3

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,364 changes: 211 additions & 1,153 deletions package-lock.json

Large diffs are not rendered by default.

31 changes: 26 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,45 @@
"preferences": [
{
"name": "nwcurl",
"title": "NWC connection details",
"description": "Your NWC wallet connection details",
"placeholder": "nostr+walletconnect://...",
"type": "password",
"required": true
},
{
"name": "currency",
"title": "Currency",
"description": "You preferred currency to see amounts",
"type": "dropdown",
"data": [
{
"title": "USD",
"value": "USD"
},
{
"title": "EUR",
"value": "EUR"
},
{
"title": "GBP",
"value": "GBP"
}
],
"required": true,
"title": "NWC connection details"
"default": "USD"
}
],
"commands": [
{
"name": "pay",
"name": "send",
"title": "Send",
"keywords": ["send", "pay", "wallet", "invoice", "lnurl", "lightning"],
"subtitle": "Send to lightning address or pay lightning invoice",
"description": "Send to lightning address or pay lightning invoice",
"icon": "send.png",
"mode": "view",
"script": "src/Pay.tsx",
"script": "src/Send.tsx",
"arguments": [
{
"name": "input",
Expand Down Expand Up @@ -79,7 +101,6 @@
"@types/react": "18.2.27",
"eslint": "^8.51.0",
"prettier": "^3.0.3",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"scripts": {
Expand All @@ -90,6 +111,6 @@
"publish": "npx @raycast/api@latest publish"
},
"version": "1.0.0",
"main": "index.js",
"main": "src/index.js",
"keywords": []
}
18 changes: 15 additions & 3 deletions src/Balance.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import React, { useEffect, useState } from "react";
import { ActionPanel, Detail, Action, showToast, Toast } from "@raycast/api";
import "cross-fetch/polyfill";
import { useEffect, useState } from "react";
import { ActionPanel, Detail, Action, showToast, Toast, getPreferenceValues } from "@raycast/api";
import { fiat } from "@getalby/lightning-tools";
import { connectWallet } from "./wallet";

export default function ShowBalance() {
const [balance, setBalance] = useState<string | null>(null);
const [fiatBalance, setFiatBalance] = useState<string | null>(null);

const updateBalance = async () => {
const preferences = getPreferenceValues<{ currency: string }>();
const fiatCurrency = preferences.currency;

try {
const nwc = await connectWallet(); // Connect and get the wallet instance
const balanceInfo = await nwc.getBalance(); // Fetch the balance from the connected wallet
const fiatBalance = await fiat.getFormattedFiatValue({
satoshi: balanceInfo.balance,
currency: fiatCurrency,
locale: "en",
});
setBalance(`${new Intl.NumberFormat().format(balanceInfo.balance)} sats`);
setFiatBalance(fiatBalance);
} catch (error) {
if (error instanceof Error) {
showToast(Toast.Style.Failure, "Failed to fetch wallet balance", error.message);
Expand All @@ -24,7 +36,7 @@ export default function ShowBalance() {

return (
<Detail
markdown={`# Wallet Balance\nYour balance is: ${balance ?? "Loading..."}`}
markdown={`# Wallet Balance\nYour balance is: ${balance} (${fiatBalance})`}
actions={
<ActionPanel>
<Action title="Refresh" onAction={updateBalance} />
Expand Down
1 change: 0 additions & 1 deletion src/CreateInvoice.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// SendInvoice.tsx
import { setInterval } from "timers";
import React, { useState, useRef, useEffect } from "react";
import { Form, Detail, ActionPanel, Action, Icon, showToast, environment, Toast } from "@raycast/api";
Expand Down
6 changes: 4 additions & 2 deletions src/ListTransactions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import { useEffect, useState } from "react";
import { List, showToast, Toast, Icon, ActionPanel, Action, Color } from "@raycast/api";
import { connectWallet } from "./wallet";

Expand Down Expand Up @@ -63,7 +63,9 @@ export default function Transactions() {
<List.Item
key={transaction.payment_hash}
title={`${new Intl.NumberFormat().format(transaction.amount)} sats`}
subtitle={`${transaction.description ? `for ${transaction.description}` : ""} ${transaction.settled_at ? new Date(transaction.settled_at * 1000).toLocaleString() : ""}`}
subtitle={`${transaction.description ? `for ${transaction.description}` : ""} ${
transaction.settled_at ? new Date(transaction.settled_at * 1000).toLocaleString() : ""
}`}
icon={transaction.type === "incoming" ? IncomingIcon : OutgoingIcon}
actions={
<ActionPanel title={`Payment ${transaction.description}`}>
Expand Down
2 changes: 1 addition & 1 deletion src/PayInvoice.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "cross-fetch/polyfill";
import React, { useState, useEffect } from "react";
import { useState, useEffect } from "react";
import { Form, ActionPanel, Action, showToast, Toast, popToRoot } from "@raycast/api";
import { Invoice } from "@getalby/lightning-tools";

Expand Down
2 changes: 1 addition & 1 deletion src/PayLightningAddress.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "cross-fetch/polyfill";
import React, { useState, useEffect, useRef } from "react";
import { useState, useEffect, useRef } from "react";

import { Form, ActionPanel, Action, showToast, Toast, popToRoot, Clipboard } from "@raycast/api";
import { LightningAddress } from "@getalby/lightning-tools";
Expand Down
4 changes: 2 additions & 2 deletions src/Pay.tsx → src/Send.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import "cross-fetch/polyfill";
import React, { useState, useEffect } from "react";
import { useState, useEffect } from "react";

import { Form, ActionPanel, Action, Clipboard, getSelectedText, LaunchProps } from "@raycast/api";
import { LightningAddress, Invoice } from "@getalby/lightning-tools";

import PayInvoice from "./PayInvoice";
import PayToLightingAddress from "./PayLightningAddress";

export default function Pay(props: LaunchProps<{ arguments: Arguments.Pay }>) {
export default function Send(props: LaunchProps<{ arguments: Arguments.Send }>) {
const [lightningAddress, setLightningAddress] = useState("");
const [invoice, setInvoice] = useState("");
const [input, setInput] = useState(props.arguments.input);
Expand Down
33 changes: 0 additions & 33 deletions src/WalletDashboardComponent.tsx

This file was deleted.

24 changes: 0 additions & 24 deletions src/utils/connectWallet.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/utils/storage.ts

This file was deleted.

Loading