Skip to content

Commit

Permalink
Merge branch 'main' into ux-updates-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
ericspaghetti committed May 19, 2024
2 parents 05a04bc + 3d608e1 commit dbc8de2
Show file tree
Hide file tree
Showing 29 changed files with 1,693 additions and 821 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x

# ESLint and Prettier must be in `package.json`
- name: Install Node.js dependencies
Expand Down
1 change: 1 addition & 0 deletions .replit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
run = "npm run dev"
modules = ["nodejs-20:v8-20230920-bd784b9"]

[nix]
channel = "stable-22_11"
Expand Down
13 changes: 13 additions & 0 deletions components/display-products.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const DisplayEvents = ({

const router = useRouter();

const { userPubkey } = getLocalStorageData();

useEffect(() => {
setIsLoading(productEventContext.isLoading);
}, [productEventContext.isLoading]);
Expand Down Expand Up @@ -79,6 +81,17 @@ const DisplayEvents = ({
handleSendMessage: (pubkeyToOpenChatWith: string) => void,
) => {
if (focusedPubkey && productData.pubkey !== focusedPubkey) return;

if (
(productData.pubkey ===
"95a5e73109d4c419456372ce99bbf5823dfb6f77aed58d03f77ea052f150ee4a" ||
productData.pubkey ===
"773ed8aba7ee59f6f24612533e891450b6197b5ca24e7680209adb944e330e2f") &&
userPubkey !== productData.pubkey
) {
return; // temp fix, add adult categories or separate from global later
}

return (
<ProductCard
key={productData.id + "-" + index}
Expand Down
27 changes: 17 additions & 10 deletions components/invoice-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ import {
formatWithCommas,
} from "./utility-components/display-monetary-info";
import { SHOPSTRBUTTONCLASSNAMES } from "./utility/STATIC-VARIABLES";
import { captureInvoicePaidmetric } from "./utility/metrics-helper-functions";
import {
captureCashuPaidMetric,
captureInvoicePaidmetric,
} from "./utility/metrics-helper-functions";
import SignInModal from "./sign-in/SignInModal";

export default function InvoiceCard({
Expand Down Expand Up @@ -94,9 +97,10 @@ export default function InvoiceCard({
setName(profile && profile.content.name ? profile.content.name : userNPub);
}, [profileContext]);

const handleLightningPayment = async (newPrice: number, currency: string) => {
const handleLightningPayment = async () => {
let newPrice = totalCost;
const wallet = new CashuWallet(new CashuMint(mints[0]));
if (currency === "USD") {
if (currency.toUpperCase() === "USD") {
try {
const res = await axios.get(
"https://api.coinbase.com/v2/prices/BTC-USD/spot",
Expand Down Expand Up @@ -157,7 +161,7 @@ export default function InvoiceCard({

if (encoded) {
sendTokens(encoded);
captureInvoicePaidmetric(metricsInvoiceId, productData.id);
captureInvoicePaidmetric(metricsInvoiceId, productData);
setPaymentConfirmed(true);
setQrCodeUrl(null);
if (setInvoiceIsPaid) {
Expand Down Expand Up @@ -225,8 +229,9 @@ export default function InvoiceCard({

const formattedTotalCost = formatWithCommas(totalCost, currency);

const handleCashuPayment = async (price: number, currency: string) => {
const handleCashuPayment = async () => {
try {
let price = totalCost;
const mint = new CashuMint(mints[0]);
const wallet = new CashuWallet(mint);
if (currency === "USD") {
Expand Down Expand Up @@ -255,9 +260,11 @@ export default function InvoiceCard({
},
],
});
sendTokens(encodedSendToken);
// captureInvoicePaidmetric(metricsInvoiceId, productData.id);
// another metric to capture native Cashu payments is needed
sendTokens(encodedSendToken)
.then(() => {
captureCashuPaidMetric(productData);
})
.catch(console.log);
const changeProofs = tokenToSend?.returnChange;
const remainingProofs = tokens.filter(
(p: Proof) => !mintKeySetIds?.includes(p.id),
Expand Down Expand Up @@ -313,7 +320,7 @@ export default function InvoiceCard({
return;
}
if (randomNsec !== "") {
handleLightningPayment(totalCost, currency);
handleLightningPayment();
}
setShowInvoiceCard(true);
}}
Expand All @@ -333,7 +340,7 @@ export default function InvoiceCard({
return;
}
if (randomNsec !== "") {
handleCashuPayment(totalCost, currency);
handleCashuPayment();
}
}}
startContent={
Expand Down
4 changes: 2 additions & 2 deletions components/messages/chat-message.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getLocalStorageData } from "../utility/nostr-helper-functions";
import RedeemButton from "../utility-components/redeem-button";
import ClaimButton from "../utility-components/claim-button";
import { NostrMessageEvent } from "../../utils/types/types";
import { timeSinceMessageDisplayText } from "../../utils/messages/utils";

Expand Down Expand Up @@ -56,7 +56,7 @@ export const ChatMessage = ({
tokenAfterCashuA ? (
<>
{messageEvent.content}
<RedeemButton token={tokenAfterCashuA} />
<ClaimButton token={tokenAfterCashuA} />
</>
) : (
<>{messageEvent.content}</>
Expand Down
64 changes: 34 additions & 30 deletions components/messages/chat-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export const ChatPanel = ({
currentChatPubkey,
chatsMap,
isSendingDMLoading,
isPayment,
}: {
handleGoBack: () => void;
handleSendMessage: (message: string) => void;
currentChatPubkey: string;
chatsMap: Map<string, ChatObject>;
isSendingDMLoading: boolean;
isPayment: boolean;
}) => {
const [messageInput, setMessageInput] = useState("");
const [messages, setMessages] = useState<NostrMessageEvent[]>([]); // [chatPubkey, chat]
Expand Down Expand Up @@ -61,8 +63,8 @@ export const ChatPanel = ({
};

return (
<div className="absolute top-0 z-20 flex h-full w-full flex-col overflow-clip bg-light-bg px-2 dark:bg-dark-bg md:relative md:h-[85vh]">
<h2 className="mt-2 flex h-[60px] w-full flex-row items-center overflow-clip pr-2 align-middle text-shopstr-purple-light dark:text-shopstr-yellow-light">
<div className="absolute flex h-full w-full flex-col overflow-clip bg-light-bg px-2 pb-20 dark:bg-dark-bg md:relative md:h-[85vh] md:pb-0 lg:pb-0">
<h2 className="flex h-[60px] w-full flex-row items-center overflow-clip align-middle text-shopstr-purple-light dark:text-shopstr-yellow-light">
<ArrowUturnLeftIcon
onClick={handleGoBack}
className="mx-3 h-9 w-9 cursor-pointer rounded-md p-1 text-shopstr-purple-light hover:bg-shopstr-yellow hover:text-purple-700 dark:text-shopstr-yellow-light hover:dark:bg-shopstr-purple"
Expand All @@ -86,34 +88,36 @@ export const ChatPanel = ({
})}
<div ref={bottomDivRef} />
</div>
<div className="space-x flex items-center p-2 pb-20 md:pb-0 lg:pb-0">
<Input
className="pr-3 text-light-text dark:text-dark-text"
type="text"
width="100%"
size="md"
value={messageInput}
placeholder="Type your message..."
onChange={(e) => {
setMessageInput(e.target.value);
}}
onKeyDown={(e) => {
if (
e.key === "Enter" &&
!(messageInput === "" || isSendingDMLoading)
)
sendMessage();
}}
/>
<Button
className={SHOPSTRBUTTONCLASSNAMES}
isDisabled={messageInput === "" || isSendingDMLoading}
isLoading={isSendingDMLoading}
onClick={sendMessage}
>
Send
</Button>
</div>
{!isPayment && (
<div className="space-x flex items-center p-2">
<Input
className="pr-3 text-light-text dark:text-dark-text"
type="text"
width="100%"
size="md"
value={messageInput}
placeholder="Type your message..."
onChange={(e) => {
setMessageInput(e.target.value);
}}
onKeyDown={(e) => {
if (
e.key === "Enter" &&
!(messageInput === "" || isSendingDMLoading)
)
sendMessage();
}}
/>
<Button
className={SHOPSTRBUTTONCLASSNAMES}
isDisabled={messageInput === "" || isSendingDMLoading}
isLoading={isSendingDMLoading}
onClick={sendMessage}
>
Send
</Button>
</div>
)}
</div>
);
};
Expand Down
Loading

0 comments on commit dbc8de2

Please sign in to comment.