Skip to content

Commit

Permalink
Merge branch 'main' into auction
Browse files Browse the repository at this point in the history
  • Loading branch information
hakymulla authored Dec 1, 2024
2 parents 81370ec + c8e5b54 commit 19c9425
Show file tree
Hide file tree
Showing 53 changed files with 6,633 additions and 1,217 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ pnpm-lock.yaml
.vercel

onchain/cairo/.snfoundry_cache/https___starknet_mainnet_public_blastapi_io_rpc_v0_7_615925_v3.json
onchain/cairo/.snfoundry_cache/https___starknet_sepolia_public_blastapi_io_rpc_v0_7_505925_v3.json
onchain/cairo/.snfoundry_cache/https___starknet_sepolia_public_blastapi_io_rpc_v0_7_615925_v3.json


13 changes: 13 additions & 0 deletions apps/indexer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ services:
- backend
restart: on-failure

nameservice-indexer:
environment:
- AUTH_TOKEN=${AUTH_TOKEN}
- POSTGRES_CONNECTION_STRING=postgresql://admin:postgres@postgres:5432/indexer
image: quay.io/apibara/sink-postgres:latest
command: 'run ./indexer/nameservice.ts --allow-env-from-env AUTH_TOKEN,POSTGRES_CONNECTION_STRING,LAUNCHPAD_ADDRESS,ENV_STREAM_URL -A ${AUTH_TOKEN}'
volumes:
- ./src:/indexer
depends_on:
- postgres
networks:
- backend
restart: on-failure


networks:
Expand Down
8 changes: 6 additions & 2 deletions apps/indexer/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const LAUNCHPAD_ADDRESS = {
// SEPOLIA:"0x5ea5ae49d6449896e096c567350ac639604426c61b16671c37fd9b196ec7fa9",
// SEPOLIA:"0x732f0364e664ab984049552dcd0aedf7c591ade35d5f3b82e141dd1c987af07"
// SEPOLIA:Deno.env.get("LAUNCHPAD_ADDRESS") ??"0x4fd0893672b60a123606ec9e492e54e795a13e969c6c2600195dcea956ada5d"
SEPOLIA:Deno.env.get("LAUNCHPAD_ADDRESS") ??"0x1e00d0d7167938c2aa289850c96d7129ff16c1ed02b7542030bc2e39dc41885"
// SEPOLIA:Deno.env.get("LAUNCHPAD_ADDRESS") ??"0x1e00d0d7167938c2aa289850c96d7129ff16c1ed02b7542030bc2e39dc41885"
SEPOLIA:Deno.env.get("LAUNCHPAD_ADDRESS") ??"0x2eb4dac724b4507becc409667bdea68d697665e182702f294eb5bd8bfb28e26"



};
export {
constants
Expand All @@ -16,7 +20,7 @@ export const UNRUGGABLE_FACTORY_ADDRESS = "0x01a46467a9246f45c8c340f1f155266a26a
export const NAMESERVICE_ADDRESS = {
// SEPOLIA: "0x595d9c14d5b52bae1bd5a88f3aefb521eca956fde4de95e400197f1080fa862",
// SEPOLIA:"0x4fe0ee38c814e0599a5140c5673a233d227ce0be9e22c3acdbee15ac9aefc10"
SEPOLIA: "0x15dcd3c28c07846fa98d3a40d29446de21b5e6cd8d49a43773da0f237d5ea7f"
SEPOLIA: "0x6e8ecfa6872bd27a7517077069b401a494687e66e2a98d37311eee1d96f1b57"

};
export const SEPOLIA_STREAM_URL="https://sepolia.starknet.a5a.ch"
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@babel/runtime": "^7.24.8",
"@cashu/cashu-ts": "^1.2.1",
"@cashu/cashu-ts": "^2.0.0",
"@docusaurus/core": "^3.5.2",
"@docusaurus/preset-classic": "^3.5.2",
"@dynamic-labs/client": "4.0.0-alpha.8",
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/src/constants/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export enum EventKey {
ClaimEvent = '0x1338111cc170c56fecb176d35cca4c04823f0b8d9c64cfb956c97b236ea6fc6',
}

export const DEFAULT_TIMELOCK = 7 * 24 * 60 * 60 * 1_000; // 7 days
export const DEFAULT_TIMELOCK = 0; // 7 days
// export const DEFAULT_TIMELOCK = 7 * 24 * 60 * 60 * 1_000; // 7 days

export const WEB_MAX_WIDTH = 520;

Expand Down
113 changes: 47 additions & 66 deletions apps/mobile/src/hooks/usePayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,66 +37,54 @@ export const usePayment = () => {
if (!wallet) {
return undefined;
} else if (proofs) {
const proofsSpent = await wallet.checkProofsSpent(proofs);
let proofsCopy = Array.from(proofs);

if (proofsSpent) {
proofsCopy = proofsCopy?.filter((p) => !proofsSpent?.includes(p));
}

if (proofsCopy.length > 0) {
try {
const response = await meltTokens(pInvoice, proofsCopy);
if (response) {
const {meltQuote, meltResponse, proofsToKeep, remainingProofs, selectedProofs} =
response;
setProofsFilter(selectedProofs);
if (privateKey && publicKey) {
await refetchTokens();
await deleteMultiple(
filteredTokenEvents.map((event) => event.id),
'proofs spent in transaction',
);
const tokenEvent = await createTokenEvent({
walletId,
mint: activeMint,
proofs: proofsToKeep,
});
const destroyedEvents = filteredTokenEvents.map((event) => ({
id: event.id,
marker: 'destroyed' as EventMarker,
}));
await createSpendingEvent({
walletId,
direction: 'out',
amount: (meltQuote.amount + meltQuote.fee_reserve).toString(),
unit: activeUnit,
events: [...destroyedEvents, {id: tokenEvent.id, marker: 'created' as EventMarker}],
});
}
showToast({
title: 'Payment sent.',
type: 'success',
try {
const response = await meltTokens(pInvoice, proofs);
if (response) {
const {meltQuote, meltResponse, proofsToKeep, remainingProofs, selectedProofs} = response;
setProofsFilter(selectedProofs);
if (privateKey && publicKey) {
await refetchTokens();
await deleteMultiple(
filteredTokenEvents.map((event) => event.id),
'proofs spent in transaction',
);
const tokenEvent = await createTokenEvent({
walletId,
mint: activeMint,
proofs: proofsToKeep,
});
setProofs([...remainingProofs, ...proofsToKeep]);
setProofsStorage([...remainingProofs, ...proofsToKeep]);
const newInvoice: ICashuInvoice = {
amount: -(meltQuote.amount + meltQuote.fee_reserve),
bolt11: pInvoice,
quote: meltQuote.quote,
date: Date.now(),
state: MintQuoteState.PAID,
const destroyedEvents = filteredTokenEvents.map((event) => ({
id: event.id,
marker: 'destroyed' as EventMarker,
}));
await createSpendingEvent({
walletId,
direction: 'out',
};
setTransactions([...transactions, newInvoice]);
return meltResponse;
} else {
return undefined;
amount: (meltQuote.amount + meltQuote.fee_reserve).toString(),
unit: activeUnit,
events: [...destroyedEvents, {id: tokenEvent.id, marker: 'created' as EventMarker}],
});
}
} catch (error) {
showToast({
title: 'Payment sent.',
type: 'success',
});
setProofs([...remainingProofs, ...proofsToKeep]);
setProofsStorage([...remainingProofs, ...proofsToKeep]);
const newInvoice: ICashuInvoice = {
amount: -(meltQuote.amount + meltQuote.fee_reserve),
bolt11: pInvoice,
quote: meltQuote.quote,
date: Date.now(),
state: MintQuoteState.PAID,
direction: 'out',
};
setTransactions([...transactions, newInvoice]);
return meltResponse;
} else {
return undefined;
}
} else {
} catch (error) {
return undefined;
}
} else {
Expand All @@ -116,12 +104,7 @@ export const usePayment = () => {
}

if (proofs) {
const proofsSpent = await wallet.checkProofsSpent(proofs);
let proofsCopy = Array.from(proofs);

if (proofsSpent) {
proofsCopy = proofsCopy?.filter((p) => !proofsSpent?.includes(p));
}
const proofsCopy = Array.from(proofs);

const availableAmount = proofsCopy.reduce((s, t) => (s += t.amount), 0);

Expand All @@ -142,10 +125,7 @@ export const usePayment = () => {
}
}

const {returnChange: proofsToKeep, send: proofsToSend} = await wallet.send(
amount,
selectedProofs,
);
const {keep: proofsToKeep, send: proofsToSend} = await wallet.send(amount, selectedProofs);

if (proofsToKeep && proofsToSend) {
if (privateKey && publicKey) {
Expand Down Expand Up @@ -175,7 +155,8 @@ export const usePayment = () => {
setProofsStorage([...remainingProofs, ...proofsToKeep]);

const token = {
token: [{proofs: proofsToSend, mint: activeMint}],
mint: activeMint,
proofs: proofsToSend,
activeUnit,
} as Token;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import '../../../../../applyGlobalPolyfills';

import {MintQuoteResponse, MintQuoteState, Proof} from '@cashu/cashu-ts';
import {MintQuoteResponse, MintQuoteState} from '@cashu/cashu-ts';
import {ICashuInvoice, useAuth, useCreateSpendingEvent, useCreateTokenEvent} from 'afk_nostr_sdk';
import * as Clipboard from 'expo-clipboard';
import React, {useState} from 'react';
Expand Down Expand Up @@ -126,7 +126,7 @@ export const Invoices = () => {
const tokenEvent = await createTokenEvent({
walletId,
mint: activeMint,
proofs: receive?.proofs,
proofs: receive,
});
await createSpendingEvent({
walletId,
Expand All @@ -137,11 +137,11 @@ export const Invoices = () => {
});
}
if (!proofsStorage && !proofs) {
setProofsStorage([...(receive?.proofs as Proof[])]);
setProofs([...(receive?.proofs as Proof[])]);
setProofsStorage([...receive]);
setProofs([...receive]);
} else {
setProofsStorage([...proofs, ...(receive?.proofs as Proof[])]);
setProofs([...proofs, ...(receive?.proofs as Proof[])]);
setProofsStorage([...proofs, ...receive]);
setProofs([...proofs, ...receive]);
}
return receive;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/modules/CashuWallet/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default ThemedStyleSheet((theme) => ({
padding: Spacing.medium,
borderRadius: 10,
flex: 1,
backgroundColor: 'transparent',
backgroundColor: theme.colors.background,
color: theme.colors.text,
},
modalBackdrop: {
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/modules/TipModal/starknet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const TipModalStarknet = forwardRef<Modalize, TipModalStarknetProps>(

const account = useAccount();
const walletModal = useWalletModal();
const {sendTransaction} = useTransaction({callsProps:[]});
const {sendTransaction} = useTransaction({});
const {hide: hideTransactionModal} = useTransactionModal();
const waitConnection = useWaitConnection();

Expand Down
7 changes: 1 addition & 6 deletions apps/mobile/src/screens/Cashu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React from 'react';
import {ScrollView} from 'react-native';

import {CashuView} from '../../modules/CashuWallet';
import {CashuWalletScreenProps} from '../../types';
export const CashuScreen: React.FC<CashuWalletScreenProps> = () => {
return (
<ScrollView showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false}>
<CashuView></CashuView>
</ScrollView>
);
return <CashuView></CashuView>;
};
10 changes: 5 additions & 5 deletions apps/mobile/src/screens/ReceiveEcash/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ReceiveEcash: React.FC<ReceiveEcashScreenProps> = ({navigation, rou
const {publicKey, privateKey} = useAuth();

const {handleReceiveEcash} = usePayment();
const {mints, setMints, setActiveMint, buildMintData, setActiveUnit, wallet} = useCashuContext()!;
const {mints, setMints, setActiveMint, buildMintData, setActiveUnit} = useCashuContext()!;
const {value: mintsStorage, setValue: setMintsStorage} = useMintStorage();
const {setValue: setActiveMintStorage} = useActiveMintStorage();
const {setValue: setActiveUnitStorage} = useActiveUnitStorage();
Expand All @@ -53,7 +53,7 @@ export const ReceiveEcash: React.FC<ReceiveEcashScreenProps> = ({navigation, rou
const decodedToken = getDecodedToken(token);
setTokenInfo(decodedToken);
if (decodedToken && mintsStorage.length === 0) {
const mintUrl = decodedToken.token[0].mint;
const mintUrl = decodedToken.mint;
handleAddMint(mintUrl);
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ export const ReceiveEcash: React.FC<ReceiveEcashScreenProps> = ({navigation, rou

const handleReceive = async () => {
setIsProcessing(true);
const mintUrl = tokenInfo?.token?.[0].mint;
const mintUrl = tokenInfo?.mint;
if (mintUrl) {
const mintAlreadyConfigured = mintsStorage?.some((mint) => mint.url === mintUrl) || false;
if (!mintAlreadyConfigured) {
Expand Down Expand Up @@ -141,8 +141,8 @@ export const ReceiveEcash: React.FC<ReceiveEcashScreenProps> = ({navigation, rou
<View style={styles.warningContainer}>
<InfoIcon width={30} height={30} color={theme.colors.primary} />
<Text style={styles.warning}>
This will connect the mint <b>{tokenInfo?.token?.[0].mint}</b> to your session if
it&apos;s not already configured.
This will connect the mint <b>{tokenInfo?.mint}</b> to your session if it&apos;s not
already configured.
</Text>
</View>
<Button
Expand Down
12 changes: 5 additions & 7 deletions apps/pwa/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import './index.css';
import '@rainbow-me/rainbowkit/styles.css';

import {Box} from '@chakra-ui/react';
import type {Metadata} from 'next';
// import {useRouter} from 'next/router';
import Script from 'next/script';
Expand Down Expand Up @@ -32,7 +31,7 @@ export default function RootLayout({children}: {children: React.ReactNode}) {
// }, [router.events]);
return (
<html lang="en">
<Providers>
<head>
<Script
strategy="afterInteractive"
src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
Expand All @@ -51,11 +50,10 @@ export default function RootLayout({children}: {children: React.ReactNode}) {
`,
}}
/>

<body>
<Box>{children}</Box>
</body>
</Providers>
</head>
<body>
<Providers>{children}</Providers>
</body>
</html>
);
}
19 changes: 4 additions & 15 deletions apps/pwa/src/components/MenuNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,16 @@ const MenuNav: React.FC<IMenuParent> = () => {
{isOpen ? 'Close' : 'Profile'}
</MenuButton>
<MenuList>
<MenuItem>
<CustomConnectButtonWallet></CustomConnectButtonWallet>
</MenuItem>
<CustomConnectButtonWallet></CustomConnectButtonWallet>
{/* <MenuItem>
<DynamicManagement></DynamicManagement>
</MenuItem> */}
<MenuItem>
<AccountStarknet></AccountStarknet>
</MenuItem>
<AccountStarknet></AccountStarknet>
{/* Dedicated Close Button */}

{/*
{typeof window !== "undefined" && window?.Telegram?.WebApp &&
<>
</>
} */}

<MenuItem>
{typeof window !== 'undefined' && window?.Telegram?.WebApp ? (
<TelegramAccount></TelegramAccount>
</MenuItem>
) : null}

<MenuItem onClick={onClose} color="red.500" fontWeight="bold">
Close Menu
Expand Down
4 changes: 2 additions & 2 deletions apps/pwa/src/components/MobileDrawerNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ const MobileDrawerNavbar: React.FC = () => {
Pixel
</Button>
</Link>
<Link href="/gift" passHref>
{/* <Link href="/gift" passHref>
<Button variant="ghost" width="100%" onClick={onClose}>
Gift
</Button>
</Link>
</Link> */}
<ColorModeToggle></ColorModeToggle>
</VStack>
</DrawerBody>
Expand Down
Loading

0 comments on commit 19c9425

Please sign in to comment.