Skip to content

feat: team wallet #238

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

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0837342
wip
viktormarinho May 14, 2025
6bebad5
something
viktormarinho May 15, 2025
deccb7d
wip migrating wallet apis
viktormarinho May 15, 2025
8cfb516
wip
viktormarinho May 15, 2025
4d41377
wip
viktormarinho May 16, 2025
3e22546
wip
viktormarinho May 16, 2025
818e112
better
viktormarinho May 16, 2025
7b3c4b9
wip
viktormarinho May 17, 2025
30a1f35
bringing the webhook here
viktormarinho May 18, 2025
055d273
stripe webhook stuff works
viktormarinho May 18, 2025
42d514a
huh kv being versioned
viktormarinho May 18, 2025
1eed49a
workspace
viktormarinho May 19, 2025
0ea7901
fix
viktormarinho May 19, 2025
ed1b357
statements
viktormarinho May 19, 2025
ec53647
statements
viktormarinho May 19, 2025
ec33863
fix + fmt
viktormarinho May 19, 2025
8c53c87
nice chart
viktormarinho May 19, 2025
b08a700
better
viktormarinho May 19, 2025
860d00e
remove old wallet button
viktormarinho May 19, 2025
2e40be2
changes + wip voucher
viktormarinho May 20, 2025
0af69c3
format
viktormarinho May 20, 2025
2df7be0
Merge branch 'main' into team-wallet
viktormarinho May 20, 2025
5a8cceb
fix errors
viktormarinho May 20, 2025
e60a4f0
Merge branch 'main' into team-wallet
viktormarinho May 20, 2025
716e591
fi
viktormarinho May 20, 2025
f71fc62
ok
viktormarinho May 20, 2025
6e5c135
separate hooks, voucher works
viktormarinho May 21, 2025
5890936
lint
viktormarinho May 21, 2025
48555d4
format
viktormarinho May 21, 2025
763142d
optional port env var
viktormarinho May 21, 2025
44a0273
move things to remove a wallet folder
viktormarinho May 21, 2025
cdd20a1
remove logs
viktormarinho May 21, 2025
f41d4a6
fix imports + add migration
viktormarinho May 21, 2025
5d3836e
add env vars
viktormarinho May 21, 2025
4daa569
rename
viktormarinho May 21, 2025
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
6 changes: 6 additions & 0 deletions .github/workflows/deploy-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
AWS_SECRET_ACCESS_KEY
AWS_REGION
DECO_CHAT_DATA_BUCKET_NAME
STRIPE_SECRET_KEY
STRIPE_WEBHOOK_SECRET
CURRENCY_API_KEY
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_SERVER_TOKEN: ${{ secrets.SUPABASE_SERVER_TOKEN }}
Expand All @@ -72,3 +75,6 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
DECO_CHAT_DATA_BUCKET_NAME: ${{ secrets.DECO_CHAT_DATA_BUCKET_NAME }}
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }}
CURRENCY_API_KEY: ${{ secrets.CURRENCY_API_KEY }}
7 changes: 5 additions & 2 deletions apps/api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { default as app } from "./src/app.ts";
const instrumentedApp = getRuntimeKey() === "deno" ? app : instrument(app);

// Domains we consider "self"
const SELF_DOMAINS: string[] = [Hosts.API, "localhost"];
const SELF_DOMAINS: string[] = [
Hosts.API,
`localhost:${Deno.env.get("PORT") || 3001}`,
];

// Patch fetch globally
const originalFetch = globalThis.fetch;
Expand Down Expand Up @@ -43,7 +46,7 @@ globalThis.fetch = async function patchedFetch(

const context = contextStorage.getStore();

if (SELF_DOMAINS.includes(url.hostname)) {
if (SELF_DOMAINS.includes(url.host)) {
if (!context) {
throw new Error("Missing context for internal self-invocation");
}
Expand Down
3 changes: 2 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"type": "module",
"scripts": {
"dev": "deno serve -A --port 3001 --unstable-hmr --unstable-kv --env-file=../web/.env main.ts",
"dev:wrangler": "wrangler dev --port 3001"
"dev:wrangler": "wrangler dev --port 3001",
"stripe:test": "stripe fixtures testing/stripe/fixtures/workspace-wallet-deposit.json"
},
"dependencies": {
"lru-cache": "^11.1.0",
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
createMCPToolsStub,
State,
} from "./utils/context.ts";
import { handleStripeWebhook } from "./webhooks/stripe.ts";

export const app = new Hono<AppEnv>();

Expand Down Expand Up @@ -219,6 +220,9 @@ Object.entries(loginRoutes).forEach(([route, honoApp]) => {
app.route(route, honoApp);
});

// External webhooks
app.post("/webhooks/stripe", handleStripeWebhook);

// Health check endpoint
app.get("/health", (c: Context) => c.json({ status: "ok" }));

Expand Down
64 changes: 64 additions & 0 deletions apps/api/src/webhooks/stripe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { Context } from "hono";
import {
createTransactionFromStripeEvent,
serializeError,
verifyAndParseStripeEvent,
WebhookEventIgnoredError,
} from "@deco/sdk/mcp";
import { honoCtxToAppCtx } from "../api.ts";
import { createWalletClient } from "@deco/sdk/mcp/wallet";

export const handleStripeWebhook = async (c: Context) => {
try {
const signature = c.req.header("stripe-signature");
if (!signature) {
throw new Error("Stripe signature header not found");
}

const appContext = honoCtxToAppCtx(c);

const payload = await c.req.text();
const event = await verifyAndParseStripeEvent(
payload,
signature,
appContext,
);
const transaction = await createTransactionFromStripeEvent(
appContext,
event,
);

if (!appContext.envVars.WALLET_API_KEY) {
throw new Error("WALLET_API_KEY is not set");
}

const wallet = createWalletClient(
appContext.envVars.WALLET_API_KEY,
appContext.walletBinding,
);

const response = await wallet["POST /transactions"]({}, {
body: transaction,
});

if (!response.ok) {
const error = await response.text();
throw new Error(`Failed to create transaction: ${error}`);
}

return c.json({
message: "Transaction created",
}, 200);
} catch (error) {
if (error instanceof WebhookEventIgnoredError) {
return c.json({
message: error.message,
}, 400);
}

console.error("[Stripe Webhook] Error", serializeError(error));
return c.json({
message: "Internal server error",
}, 500);
}
};
47 changes: 47 additions & 0 deletions apps/api/testing/stripe/fixtures/workspace-wallet-deposit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"_meta": {
"template_version": 0
},
"fixtures": [
{
"name": "customer",
"path": "/v1/customers",
"method": "post",
"params": {
"name": "Viktor Marinho",
"email": "[email protected]",
"metadata": {
"product": "deco.chat",
"workspace": "/users/c40e818c-9a67-4dc6-ac3b-2bb6361663c2"
}
}
},
{
"name": "payment_intent",
"path": "/v1/payment_intents",
"method": "post",
"params": {
"amount": 1418,
"confirm": "true",
"metadata": {
"test": "123"
},
"customer": "${customer:id}",
"currency": "brl",
"description": "(created by Stripe CLI)",
"payment_method": "pm_card_visa",
"payment_method_types": ["card"],
"shipping": {
"name": "Jenny Rosen",
"address": {
"line1": "510 Townsend St",
"postal_code": "94103",
"city": "San Francisco",
"state": "CA",
"country": "US"
}
}
}
}
]
}
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"remark-gfm": "^4.0.1",
"tiptap-markdown": "^0.8.10",
"prismjs": "1.30.0",
"recharts": "^2.15.1",
"react-syntax-highlighter": "15.6.1",
"sonner": "^2.0.3",
"zod": "3.24.3",
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/components/about/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export function Hero({
};

const handleSecondaryButtonClick = () => {
console.log("secondary button clicked");
trackEvent("deco_chat_landing_learn_more_click", {
buttonText: secondaryButtonText,
buttonLink: secondaryButtonLink,
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/components/chat/ChatError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import {
TooltipTrigger,
} from "@deco/ui/components/tooltip.tsx";
import { useState } from "react";
import { useWorkspaceLink } from "../../hooks/useNavigateWorkspace.ts";

const WELL_KNOWN_ERROR_MESSAGES = {
InsufficientFunds: "Insufficient funds",
};

export function ChatError() {
const workspaceLink = useWorkspaceLink();
const { chat: { error }, retry, correlationIdRef } = useChatContext();
const insufficientFunds = error?.message.includes(
WELL_KNOWN_ERROR_MESSAGES.InsufficientFunds,
Expand Down Expand Up @@ -50,9 +52,9 @@ export function ChatError() {
className="bg-background hover:bg-background/80 shadow-none border border-input py-3 px-4 h-10"
asChild
>
<Link to="/wallet">
<Link to={workspaceLink("/settings")}>
<Icon name="wallet" className="mr-2" />
Add funds to your wallet
Add funds to the workspace wallet
</Link>
</Button>
</div>
Expand Down
1 change: 0 additions & 1 deletion apps/web/src/components/common/InviteTeamMembersDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export function InviteTeamMembersDialog({
const openDialog = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
console.log("Opening dialog manually");
setTimeout(() => {
setIsOpen(true);
}, 50);
Expand Down
Loading