Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

cleanup

Kiran K298254efa30c
diff --git a/apps/web/.env.example b/apps/web/.env.example
index c5f532c823..d68aa44328 100644
--- a/apps/web/.env.example
+++ b/apps/web/.env.example
@@ -60,7 +60,6 @@ STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=
# Stripe App
-STRIPE_APP_INSTALL_URL=
STRIPE_APP_WEBHOOK_SECRET=
# Shopify App webhook events
diff --git a/apps/web/lib/actions/get-integration-install-url.ts b/apps/web/lib/actions/get-integration-install-url.ts
index a70a8254c6..199ef634ca 100644
--- a/apps/web/lib/actions/get-integration-install-url.ts
+++ b/apps/web/lib/actions/get-integration-install-url.ts
@@ -1,7 +1,6 @@
"use server";
import { getSlackInstallationUrl } from "../integrations/slack/install";
-import { getStripeInstallationUrl } from "../integrations/stripe/install";
import z from "../zod";
import { authActionClient } from "./safe-action";
@@ -19,12 +18,7 @@ export const getIntegrationInstallUrl = authActionClient
let url: string | null = null;
- if (integrationSlug === "stripe") {
- if (!workspace.conversionEnabled) {
- throw new Error("Conversions feature is not enabled.");
- }
- url = await getStripeInstallationUrl(workspace.id);
- } else if (integrationSlug === "slack") {
+ if (integrationSlug === "slack") {
url = await getSlackInstallationUrl(workspace.id);
} else {
throw new Error("Invalid integration slug");
diff --git a/apps/web/lib/integrations/stripe/install.ts b/apps/web/lib/integrations/stripe/install.ts
deleted file mode 100644
index d475be4fc2..0000000000
--- a/apps/web/lib/integrations/stripe/install.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import { APP_DOMAIN_WITH_NGROK, nanoid } from "@dub/utils";
-import { redis } from "../../upstash";
-import z from "../../zod";
-
-const envSchema = z.object({
- STRIPE_APP_INSTALL_URL: z.string(),
-});
-
-export const getStripeInstallationUrl = async (workspaceId: string) => {
- const state = nanoid(16);
- await redis.set(`stripe:install:state:${state}`, workspaceId, {
- ex: 30 * 60,
- });
-
- const env = envSchema.safeParse(process.env);
-
- if (!env.success) {
- throw new Error(
- "Stripe App environment variables are not configured properly.",
- );
- }
-
- const { STRIPE_APP_INSTALL_URL } = env.data;
-
- const url = new URL(STRIPE_APP_INSTALL_URL);
- url.searchParams.set(
- "redirect_uri",
- `${APP_DOMAIN_WITH_NGROK}/api/stripe/integration/callback`,
- );
- url.searchParams.set("state", state);
-
- return url.toString();
-};
diff --git a/packages/stripe-app/src/views/AppSettings.tsx b/packages/stripe-app/src/views/AppSettings.tsx
index ef933f6457..8318df0cbf 100644
--- a/packages/stripe-app/src/views/AppSettings.tsx
+++ b/packages/stripe-app/src/views/AppSettings.tsx
@@ -17,6 +17,10 @@ import { getOAuthUrl, getToken, getUserInfo } from "../utils/oauth";
import { setSecret } from "../utils/secrets";
import { Workspace } from "../utils/types";
+// TODO:
+// Handle errors and display them to the user
+// Proper loading state
+
// You don't need an API Key here, because the app uses the
// dashboard credentials to make requests.
const stripe: Stripe = new Stripe(STRIPE_API_KEY, {
@@ -24,16 +28,13 @@ const stripe: Stripe = new Stripe(STRIPE_API_KEY, {
apiVersion: "2023-08-16",
});
-const AppSettings = ({
- userContext,
- environment,
- appContext,
- oauthContext,
-}: ExtensionContextValue) => {
+const AppSettings = ({ userContext, oauthContext }: ExtensionContextValue) => {
const credentialsUsed = useRef(false);
const [oauthState, setOAuthState] = useState("");
const [challenge, setChallenge] = useState("");
const [workspace, setWorkspace] = useState<Workspace | null>(null);
+ const [disconnecting, setDisconnecting] = useState(false);
+ const [connecting, setConnecting] = useState(false);
const code = oauthContext?.code;
const verifier = oauthContext?.verifier;
@@ -41,6 +42,8 @@ const AppSettings = ({
// Verify token and connect workspace
const verifyTokenAndConnectWorkspace = async () => {
+ setConnecting(true);
+
if (!code || !verifier) {
return;
}
@@ -51,12 +54,6 @@ const AppSettings = ({
return;
}
- await setSecret({
- stripe,
- name: "dub_token",
- payload: JSON.stringify(token),
- });
-
const workspace = await getUserInfo({ token });
if (!workspace) {
@@ -69,14 +66,23 @@ const AppSettings = ({
accountId: userContext.account.id,
});
- await setSecret({
- stripe,
- name: "dub_workspace",
- payload: JSON.stringify(workspace),
- });
+ await Promise.all([
+ setSecret({
+ stripe,
+ name: "dub_workspace",
+ payload: JSON.stringify(workspace),
+ }),
+
+ setSecret({
+ stripe,
+ name: "dub_token",
+ payload: JSON.stringify(token),
+ }),
+ ]);
credentialsUsed.current = true;
setWorkspace(workspace);
+ setConnecting(false);
};
// Fetch the workspace for the current account
@@ -112,25 +118,26 @@ const AppSettings = ({
if (workspace) {
return (
<Banner
- type="default"
- title="Dub account"
- description={`Connected to Acme Inc.`}
+ title="Dub workspace"
+ description={`Connected to ${workspace.name}`}
actions={
<Button
- onPress={() => {
- if (!workspace) {
- return;
- }
+ type="destructive"
+ size="small"
+ disabled={disconnecting}
+ onPress={async () => {
+ setDisconnecting(true);
- disconnectWorkspace({
+ await disconnectWorkspace({
stripe,
workspaceId: workspace.id,
});
setWorkspace(null);
+ setDisconnecting(false);
}}
>
- Disconnect
+ {disconnecting ? "Disconnecting..." : "Disconnect"}
</Button>
}
/>
@@ -141,13 +148,15 @@ const AppSettings = ({
<SignInView
description="Connect your Dub workspace with Stripe to start tracking the conversions."
primaryAction={{
- label: "Connect workspace",
- href: getOAuthUrl({ state: oauthState, challenge }),
+ label: connecting ? "Connecting please wait..." : "Connect workspace",
+ href: connecting ? "#" : getOAuthUrl({ state: oauthState, challenge }),
}}
footerContent={
<>
Don't have an Dub account?{" "}
- <Link href="https://app.dub.co/register">Sign up</Link>
+ <Link href="https://app.dub.co/register" target="_blank" external>
+ Sign up
+ </Link>
</>
}
brandColor="#000000"