Skip to content

Commit

Permalink
feat: persist user evm address (#374)
Browse files Browse the repository at this point in the history
* feat: persist user evm address

* bump shinkai app 0.7.22
  • Loading branch information
paulclindo authored Jul 18, 2024
1 parent 105398f commit 167692e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
22 changes: 17 additions & 5 deletions apps/shinkai-desktop/src/pages/galxe-subscriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { cn } from '@shinkai_network/shinkai-ui/utils';
import { ExternalLinkIcon } from 'lucide-react';
import { useEffect } from 'react';
import { useForm } from 'react-hook-form';
import { useForm, useWatch } from 'react-hook-form';
import { Link } from 'react-router-dom';
import { toast } from 'sonner';
import { z } from 'zod';
Expand All @@ -25,6 +25,7 @@ import {
useGalxeRegisterShinkaiDesktopInstallationMutation,
} from '../lib/galxe/galxe-client';
import { useAuth } from '../store/auth';
import { useSettings } from '../store/settings';

export const RegisterShinkaiDesktopInstallationFormSchema = z.object({
address: z.string().min(42),
Expand All @@ -40,6 +41,8 @@ const SUBSCRIPTION_PATH = '/My Subscriptions';
export const GalxeSusbcriptions = () => {
const { t } = useTranslation();
const auth = useAuth((store) => store.auth);
const evmAddress = useSettings((store) => store.evmAddress);
const setEvmAddress = useSettings((store) => store.setEvmAddress);

const { inboxes } = useGetInboxes({
nodeAddress: auth?.node_address ?? '',
Expand Down Expand Up @@ -103,7 +106,7 @@ export const GalxeSusbcriptions = () => {
const form = useForm<RegisterShinkaiDesktopInstallationForm>({
resolver: zodResolver(RegisterShinkaiDesktopInstallationFormSchema),
defaultValues: {
address: '',
address: evmAddress,
signature: subscriptionsProof?.[0],
combined: subscriptionsProof?.[1],
},
Expand All @@ -125,6 +128,17 @@ export const GalxeSusbcriptions = () => {
validateQuest({ ...values });
};

const currentEvmAddress = useWatch({
control: form.control,
name: 'address',
});

useEffect(() => {
if (currentEvmAddress) {
setEvmAddress(currentEvmAddress);
}
}, [currentEvmAddress]);

useEffect(() => {
form.setValue('signature', subscriptionsProof?.[0] ?? '');
form.setValue('combined', subscriptionsProof?.[1] ?? '');
Expand Down Expand Up @@ -196,9 +210,7 @@ export const GalxeSusbcriptions = () => {
name="address"
render={({ field }) => (
<TextField
classes={{
input: 'font-mono',
}}
classes={{ input: 'font-mono' }}
endAdornment={
<div className="w-8">
<CopyToClipboardIcon
Expand Down
7 changes: 7 additions & 0 deletions apps/shinkai-desktop/src/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type SettingsStore = {
setOptInExperimental: (optInExperimental: boolean) => void;
userLanguage: LocaleMode;
setUserLanguage: (userLanguage: LocaleMode) => void;
evmAddress: string;
setEvmAddress: (evmAddress: string) => void;
};

export const useSettings = create<SettingsStore>()(
Expand Down Expand Up @@ -62,6 +64,11 @@ export const useSettings = create<SettingsStore>()(
set({ userLanguage });
switchLanguage(userLanguage);
},

evmAddress: '',
setEvmAddress: (evmAddress) => {
set({ evmAddress });
},
}),
{
name: 'settings',
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shinkai/source",
"version": "0.7.21",
"version": "0.7.22",
"license": "SEE LICENSE IN LICENSE",
"files": [
"LICENSE"
Expand Down

0 comments on commit 167692e

Please sign in to comment.