Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions ui/src/components/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const Admin: React.FC<AdminProps> = ({
const [installBundleId, setInstallBundleId] = useState<string>('');
const [creatorFacetName, setCreatorFacetName] = useState<string>('creatorFacet');
const [plannerAddress, setPlannerAddress] = useState<string>('');
const [resolverAddress, setResolverAddress] = useState<string>('');
const [environment, setEnvironment] = useState<Environment>(getInitialEnvironment());
const [ENDPOINTS, setENDPOINTS] = useState(configureEndpoints(getInitialEnvironment()));
const watcherRef = useRef<ReturnType<typeof makeAgoricChainStorageWatcher> | null>(null);
Expand Down Expand Up @@ -264,6 +265,40 @@ const Admin: React.FC<AdminProps> = ({
}
};

const handleDeliverResolverInvitation = async () => {
if (!wallet || !keplr || !chainId || !watcherRef.current) {
alert('Wallet, Keplr, chain ID, or watcher not available');
return;
}

if (!resolverAddress.trim()) {
alert('Please enter a resolver address');
return;
}

try {
const postalServiceInstance = instanceInfo?.postalService ? instances?.find(([n]) => n === 'postalService')?.[1] : null;

const { target, tools } = reifyWalletEntry<{ deliverResolverInvitation: (resolver: string, postalService: any) => Promise<any> }>({
targetName: 'creatorFacet',
wallet,
keplr,
chainId,
marshaller: watcherRef.current.marshaller,
rpcEndpoint: ENDPOINTS.RPC,
});

const invocationId = trackInvocation(tools, 'deliverResolverInvitation', 'creatorFacet');

await target.deliverResolverInvitation(resolverAddress, postalServiceInstance);
alert('Resolver invitation delivered successfully');
setResolverAddress(''); // Clear the form
} catch (error) {
console.error('Deliver resolver invitation failed:', error);
alert(`Deliver resolver invitation failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
};

const handleRedeemInvitation = async (description: string, saveName: string, replace: boolean) => {
if (!wallet || !keplr || !chainId || !watcherRef.current) {
alert('Wallet, Keplr, chain ID, or watcher not available');
Expand Down Expand Up @@ -619,8 +654,11 @@ const Admin: React.FC<AdminProps> = ({
<CreatorFacetCard
plannerAddress={plannerAddress}
setPlannerAddress={setPlannerAddress}
resolverAddress={resolverAddress}
setResolverAddress={setResolverAddress}
savedEntries={savedEntries}
onDeliverPlannerInvitation={handleDeliverPlannerInvitation}
onDeliverResolverInvitation={handleDeliverResolverInvitation}
/>

{pendingInvocations.size > 0 && (
Expand Down
42 changes: 40 additions & 2 deletions ui/src/components/CreatorFacetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ import React from 'react';
interface CreatorFacetCardProps {
plannerAddress: string;
setPlannerAddress: (value: string) => void;
resolverAddress: string;
setResolverAddress: (value: string) => void;
savedEntries: Set<string>;
onDeliverPlannerInvitation: () => void;
onDeliverResolverInvitation: () => void;
}

const CreatorFacetCard: React.FC<CreatorFacetCardProps> = ({
plannerAddress,
setPlannerAddress,
resolverAddress,
setResolverAddress,
savedEntries,
onDeliverPlannerInvitation,
onDeliverResolverInvitation,
}) => {
return (
<div style={{ border: '2px solid #28a745', padding: '1rem', borderRadius: '8px', backgroundColor: '#f8fff8' }}>
Expand All @@ -21,8 +27,8 @@ const CreatorFacetCard: React.FC<CreatorFacetCardProps> = ({
</p>

{/* Deliver Planner Invitation */}
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
<label style={{ minWidth: '140px', fontWeight: 'bold' }}>Deliver Invitation:</label>
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem', marginBottom: '0.5rem' }}>
<label style={{ minWidth: '140px', fontWeight: 'bold' }}>Planner Invitation:</label>
<input
type="text"
value={plannerAddress}
Expand Down Expand Up @@ -51,6 +57,38 @@ const CreatorFacetCard: React.FC<CreatorFacetCardProps> = ({
Deliver
</button>
</div>

{/* Deliver Resolver Invitation */}
<div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
<label style={{ minWidth: '140px', fontWeight: 'bold' }}>Resolver Invitation:</label>
<input
type="text"
value={resolverAddress}
onChange={(e) => setResolverAddress(e.target.value)}
placeholder="Resolver address (agoric1...)"
style={{
flex: 1,
padding: '0.4rem',
border: '1px solid #ccc',
borderRadius: '4px',
fontSize: '0.9em'
}}
/>
<button
onClick={onDeliverResolverInvitation}
style={{
padding: '0.4rem 0.8rem',
backgroundColor: '#28a745',
color: 'white',
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
fontSize: '0.9em'
}}
>
Deliver
</button>
</div>
</div>
);
};
Expand Down