Skip to content

Commit cc47b7b

Browse files
committed
feat: Add smart backend wallet types (#5303)
https://linear.app/thirdweb/issue/INFRA-404/add-sbw-to-dashboard <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing the backend wallet functionality within the application. It introduces new wallet types, updates wallet configuration handling, and refines the user interface for better usability. ### Detailed summary - Added `"SMART_BACKEND_WALLETS"` to the wallet type constants. - Introduced new `EngineBackendWalletType` options for smart wallets. - Updated `EngineBackendWalletOptions` with smart wallet configurations. - Changed `tabContent` to use `Partial<Record<EngineBackendWalletType, React.ReactNode>>`. - Enhanced wallet type selection logic based on smart wallet support. - Added `FormDescription` to provide information on backend wallet types. - Updated form validation to include smart wallet configurations. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 6b04d75 commit cc47b7b

File tree

4 files changed

+54
-18
lines changed

4 files changed

+54
-18
lines changed

apps/dashboard/src/@3rdweb-sdk/react/hooks/useEngine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ type EngineFeature =
116116
| "KEYPAIR_AUTH"
117117
| "CONTRACT_SUBSCRIPTIONS"
118118
| "IP_ALLOWLIST"
119-
| "HETEROGENEOUS_WALLET_TYPES";
119+
| "HETEROGENEOUS_WALLET_TYPES"
120+
| "SMART_BACKEND_WALLETS";
120121

121122
interface EngineSystemHealth {
122123
status: string;

apps/dashboard/src/app/team/[team_slug]/[project_slug]/engine/(instance)/[engineId]/configuration/components/engine-wallet-config.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ export const EngineWalletConfig: React.FC<EngineWalletConfigProps> = ({
2727
}) => {
2828
const { data: walletConfig } = useEngineWalletConfig(instance.url);
2929

30-
const tabContent: Record<EngineBackendWalletType, React.ReactNode> = {
31-
local: <LocalConfig />,
32-
"aws-kms": <KmsAwsConfig instance={instance} />,
33-
"gcp-kms": <KmsGcpConfig instance={instance} />,
34-
} as const;
30+
const tabContent: Partial<Record<EngineBackendWalletType, React.ReactNode>> =
31+
{
32+
local: <LocalConfig />,
33+
"aws-kms": <KmsAwsConfig instance={instance} />,
34+
"gcp-kms": <KmsGcpConfig instance={instance} />,
35+
} as const;
3536

3637
const [activeTab, setActiveTab] = useState<EngineBackendWalletType>("local");
3738

apps/dashboard/src/components/engine/overview/create-backend-wallet-button.tsx

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
DialogHeader,
99
DialogTitle,
1010
} from "@/components/ui/dialog";
11-
import { Form } from "@/components/ui/form";
11+
import { Form, FormDescription } from "@/components/ui/form";
1212
import { Input } from "@/components/ui/input";
1313
import {
1414
Select,
@@ -50,6 +50,11 @@ export const CreateBackendWalletButton: React.FC<
5050
instance.url,
5151
"HETEROGENEOUS_WALLET_TYPES",
5252
);
53+
const { isSupported: supportsSmartBackendWallets } = useHasEngineFeature(
54+
instance.url,
55+
"SMART_BACKEND_WALLETS",
56+
);
57+
5358
const [isOpen, setIsOpen] = useState(false);
5459
const createWallet = useEngineCreateBackendWallet(instance.url);
5560
const trackEvent = useTrack();
@@ -93,17 +98,22 @@ export const CreateBackendWalletButton: React.FC<
9398
invariant(selectedOption, "Selected a valid backend wallet type.");
9499

95100
// List all wallet types only if Engine is updated to support it.
96-
const walletTypeOptions = supportsMultipleWalletTypes
97-
? EngineBackendWalletOptions
98-
: [selectedOption];
101+
let walletTypeOptions = [selectedOption];
102+
if (supportsSmartBackendWallets) {
103+
walletTypeOptions = EngineBackendWalletOptions;
104+
} else if (supportsMultipleWalletTypes) {
105+
walletTypeOptions = EngineBackendWalletOptions.filter(
106+
({ key }) => !key.startsWith("smart:"),
107+
);
108+
}
99109

100110
const isAwsKmsConfigured = !!walletConfig.awsAccessKeyId;
101111
const isGcpKmsConfigured = !!walletConfig.gcpKmsKeyRingId;
102112

103-
const isFormValid =
104-
walletType === "local" ||
105-
(walletType === "aws-kms" && isAwsKmsConfigured) ||
106-
(walletType === "gcp-kms" && isGcpKmsConfigured);
113+
const isNotConfigured =
114+
(["aws-kms", "smart:aws-kms"].includes(walletType) &&
115+
!isAwsKmsConfigured) ||
116+
(["gcp-kms", "smart:gcp-kms"].includes(walletType) && !isGcpKmsConfigured);
107117

108118
return (
109119
<>
@@ -153,6 +163,17 @@ export const CreateBackendWalletButton: React.FC<
153163
</SelectGroup>
154164
</SelectContent>
155165
</Select>
166+
167+
<FormDescription className="py-2">
168+
Learn more about{" "}
169+
<Link
170+
href="https://portal.thirdweb.com/engine/features/backend-wallets"
171+
className="text-link-foreground hover:text-foreground"
172+
>
173+
backend wallet types
174+
</Link>
175+
.
176+
</FormDescription>
156177
</FormFieldSetup>
157178

158179
{(walletType === "aws-kms" && !isAwsKmsConfigured) ||
@@ -185,14 +206,14 @@ export const CreateBackendWalletButton: React.FC<
185206
?.message
186207
}
187208
htmlFor="wallet-label"
188-
isRequired={false}
209+
isRequired
189210
tooltip={null}
190211
>
191212
<Input
192213
id="wallet-label"
193214
type="text"
194215
placeholder="A description to identify this backend wallet"
195-
{...form.register("label")}
216+
{...form.register("label", { required: true })}
196217
/>
197218
</FormFieldSetup>
198219
)}
@@ -206,7 +227,11 @@ export const CreateBackendWalletButton: React.FC<
206227
<Button
207228
type="submit"
208229
className="min-w-28 gap-2"
209-
disabled={!isFormValid || createWallet.isPending}
230+
disabled={
231+
!form.formState.isValid ||
232+
isNotConfigured ||
233+
createWallet.isPending
234+
}
210235
>
211236
{createWallet.isPending && <Spinner className="size-4" />}
212237
Create

apps/dashboard/src/lib/engine.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
export type EngineBackendWalletType = "local" | "aws-kms" | "gcp-kms";
1+
export type EngineBackendWalletType =
2+
| "local"
3+
| "aws-kms"
4+
| "gcp-kms"
5+
| "smart:local"
6+
| "smart:aws-kms"
7+
| "smart:gcp-kms";
28

39
export const EngineBackendWalletOptions: {
410
key: EngineBackendWalletType;
@@ -7,4 +13,7 @@ export const EngineBackendWalletOptions: {
713
{ key: "local", name: "Local" },
814
{ key: "aws-kms", name: "AWS KMS" },
915
{ key: "gcp-kms", name: "Google Cloud KMS" },
16+
{ key: "smart:local", name: "Smart (Local)" },
17+
{ key: "smart:aws-kms", name: "Smart (AWS KMS)" },
18+
{ key: "smart:gcp-kms", name: "Smart (Google Cloud KMS)" },
1019
];

0 commit comments

Comments
 (0)