Skip to content

Commit

Permalink
web: fund list
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ece committed Apr 1, 2024
1 parent b4467b3 commit 4ef2cc5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 94 deletions.
34 changes: 17 additions & 17 deletions web/src/app/glam/glam-data-access.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,25 @@ export function useGlamProgramAccount({ glam }: { glam: PublicKey }) {
queryFn: () => program.account.fund.fetch(glam)
});

const close = useMutation({
mutationKey: ["glam", "close", { cluster, glam }],
mutationFn: (keypair: Keypair) =>
program.methods
.close()
.accounts({
fund: glam,
manager: keypair.publicKey
})
.signers([keypair])
.rpc(),
onSuccess: (tx) => {
transactionToast(tx);
return accounts.refetch();
}
});
// const close = useMutation({
// mutationKey: ["glam", "close", { cluster, glam }],
// mutationFn: (keypair: Keypair) =>
// program.methods
// .close()
// .accounts({
// fund: glam,
// manager: keypair.publicKey
// })
// .signers([keypair])
// .rpc(),
// onSuccess: (tx) => {
// transactionToast(tx);
// return accounts.refetch();
// }
// });

return {
account,
close
// close
};
}
13 changes: 7 additions & 6 deletions web/src/app/glam/glam-feature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WalletButton } from '../solana/solana-provider';
import { AppHero, ellipsify } from '../ui/ui-layout';
import { ExplorerLink } from '../cluster/cluster-ui';
import { useGlamProgram } from './glam-data-access';
import { CounterCreate, CounterList } from './glam-ui';
import { GlamList } from './glam-ui';

export default function CounterFeature() {
const { publicKey } = useWallet();
Expand All @@ -13,19 +13,20 @@ export default function CounterFeature() {
<div>
<AppHero
title="GLAM *.+"
subtitle={
'You can create a new fund by clicking the "Create" button. The state of the fund is stored on-chain.'
}
subtitle=""
// subtitle={
// 'You can create a new fund by clicking the "Create" button. The state of the fund is stored on-chain.'
// }
>
<p className="mb-6">
Program:&nbsp;
<ExplorerLink
path={`account/${programId}`}
label={ellipsify(programId.toString())}
/>
</p>
<CounterCreate />
</AppHero>
<CounterList />
<GlamList />
</div>
) : (
<div className="max-w-4xl mx-auto">
Expand Down
90 changes: 19 additions & 71 deletions web/src/app/glam/glam-ui.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { Keypair, PublicKey } from '@solana/web3.js';
import { useMemo } from 'react';
import { Link } from 'react-router-dom';
import { ellipsify } from '../ui/ui-layout';
import { ExplorerLink } from '../cluster/cluster-ui';
import {
useGlamProgram,
useGlamProgramAccount,
} from './glam-data-access';

export function CounterCreate() {
const { initialize } = useGlamProgram();
// export function CounterCreate() {
// const { initialize } = useGlamProgram();

return (
<button
className="btn btn-xs lg:btn-md btn-primary"
onClick={() => initialize.mutateAsync(Keypair.generate())}
disabled={initialize.isPending}
>
Create {initialize.isPending && '...'}
</button>
);
}
// return (
// <button
// className="btn btn-xs lg:btn-md btn-primary"
// onClick={() => initialize.mutateAsync(Keypair.generate())}
// disabled={initialize.isPending}
// >
// Create {initialize.isPending && '...'}
// </button>
// );
// }

export function CounterList() {
export function GlamList() {
const { accounts, getProgramAccount } = useGlamProgram();

if (getProgramAccount.isLoading) {
Expand Down Expand Up @@ -61,84 +62,31 @@ export function CounterList() {
}

function GlamCard({ glam }: { glam: PublicKey }) {
const { account, close } =
const { account } =
useGlamProgramAccount({
glam,
});

const count = useMemo(() => account.data?.assetsLen ?? 0, [account.data?.assetsLen]);

return account.isLoading ? (
<span className="loading loading-spinner loading-lg"></span>
) : (
<div className="card card-bordered border-base-300 border-4 text-neutral-content">
<div className="card card-bordered border-base-300 border-4">
<div className="card-body items-center text-center">
<div className="space-y-6">
<h2
className="card-title justify-center text-3xl cursor-pointer"
onClick={() => account.refetch()}
>
{count}
{account.data?.symbol}
</h2>
<div className="card-actions justify-around">
<button
className="btn btn-xs lg:btn-md btn-outline"
// onClick={() => increment.mutateAsync()}
// disabled={increment.isPending}
>
Increment
</button>
<button
className="btn btn-xs lg:btn-md btn-outline"
onClick={() => {
const value = window.prompt(
'Set value to:',
count.toString() ?? '0'
);
if (
!value ||
parseInt(value) === count ||
isNaN(parseInt(value))
) {
return;
}
// return set.mutateAsync(parseInt(value));
}}
// disabled={set.isPending}
>
Set
</button>
<button
className="btn btn-xs lg:btn-md btn-outline"
// onClick={() => decrement.mutateAsync()}
// disabled={decrement.isPending}
>
Decrement
</button>
</div>
<div className="text-center space-y-4">
<p>
<Link to={`/products/${glam}`}>{ellipsify(glam.toString())}</Link><br/><br/>
<ExplorerLink
path={`account/${glam}`}
label={ellipsify(glam.toString())}
label={"explorer"}
/>
</p>
<button
className="btn btn-xs btn-secondary btn-outline"
onClick={() => {
if (
!window.confirm(
'Are you sure you want to close this account?'
)
) {
return;
}
return close.mutateAsync(Keypair.generate());
}}
disabled={close.isPending}
>
Close
</button>
</div>
</div>
</div>
Expand Down

0 comments on commit 4ef2cc5

Please sign in to comment.