Skip to content

Commit ec0ee3a

Browse files
committed
feat: Add smart backend wallet types
1 parent 0660416 commit ec0ee3a

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
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/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
<>
@@ -154,6 +164,17 @@ export const CreateBackendWalletButton: React.FC<
154164
</SelectGroup>
155165
</SelectContent>
156166
</Select>
167+
168+
<FormDescription className="py-2">
169+
Learn more about{" "}
170+
<Link
171+
href="https://portal.thirdweb.com/engine/features/backend-wallets"
172+
className="text-link-foreground hover:text-foreground"
173+
>
174+
backend wallet types
175+
</Link>
176+
.
177+
</FormDescription>
157178
</FormFieldSetup>
158179

159180
{(walletType === "aws-kms" && !isAwsKmsConfigured) ||
@@ -186,14 +207,14 @@ export const CreateBackendWalletButton: React.FC<
186207
?.message
187208
}
188209
htmlFor="wallet-label"
189-
isRequired={false}
210+
isRequired
190211
tooltip={null}
191212
>
192213
<Input
193214
id="wallet-label"
194215
type="text"
195216
placeholder="A description to identify this backend wallet"
196-
{...form.register("label")}
217+
{...form.register("label", { required: true })}
197218
/>
198219
</FormFieldSetup>
199220
)}
@@ -207,7 +228,11 @@ export const CreateBackendWalletButton: React.FC<
207228
<Button
208229
type="submit"
209230
className="min-w-28 gap-2"
210-
disabled={!isFormValid || createWallet.isPending}
231+
disabled={
232+
!form.formState.isValid ||
233+
isNotConfigured ||
234+
createWallet.isPending
235+
}
211236
>
212237
{createWallet.isPending && <Spinner className="size-4" />}
213238
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)