Skip to content

Commit

Permalink
feat: show and use the latest invitations
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique authored and frazarshad committed Oct 3, 2024
1 parent 6f09752 commit 0128fd0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/components/PsmPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ProposeParamChange from './ProposeParamChange';
import ProposePauseOffers from './ProposePauseOffers';
import CharterGuidance from './CharterGuidance';
import { useAtomValue } from 'jotai';
import { walletUtilsAtom } from 'store/app';
import { rpcUtilsAtom, walletUtilsAtom } from 'store/app';

// TODO fetch list from RPC
const anchors = [
Expand Down Expand Up @@ -44,6 +44,7 @@ export default function PsmPanel() {
const [anchorName, setAnchorName] = useState(anchors[0]);
const [proposalType, setProposalType] = useState(ProposalTypes.paramChange);
const walletUtils = useAtomValue(walletUtilsAtom);
const rpcUtils = useAtomValue(rpcUtilsAtom);
const { data: walletCurrent, status } = usePublishedDatum(
walletUtils
? `wallet.${walletUtils.getWalletAddress()}.current`
Expand All @@ -54,6 +55,7 @@ export default function PsmPanel() {
status,
walletCurrent,
charterInvitationSpec.description,
rpcUtils?.agoricNames.instance.econCommitteeCharter,
);

const previousOfferId = invitationStatus.acceptedIn;
Expand Down
4 changes: 3 additions & 1 deletion src/components/VaultsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ChangeOracles, { ChangeOraclesMode } from './ChangeOracles';
import PauseLiquidations from './PauseLiquidations';
import AuctioneerParamChange from './AuctioneerParamChange';
import { useAtomValue } from 'jotai';
import { walletUtilsAtom } from 'store/app';
import { walletUtilsAtom, rpcUtilsAtom } from 'store/app';

const ProposalTypes = {
addOracles: 'Add Oracle Operators',
Expand All @@ -36,6 +36,7 @@ export default function VaultsPanel() {
ProposalTypes.managerParamChange,
);
const walletUtils = useAtomValue(walletUtilsAtom);
const rpcUtils = useAtomValue(rpcUtilsAtom);
const filterProposals = networkProposalFilter(walletUtils);

const { data: walletCurrent, status } = usePublishedDatum(
Expand All @@ -48,6 +49,7 @@ export default function VaultsPanel() {
status,
walletCurrent,
charterInvitationSpec.description,
rpcUtils?.agoricNames.instance.econCommitteeCharter,
);
const charterOfferId = charterInvitationStatus.acceptedIn;

Expand Down
11 changes: 8 additions & 3 deletions src/components/VotePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { timestampPassed } from 'utils/helpers';
import AcceptInvitation from './AcceptInvitation';
import { OfferId, VoteOnQuestion } from './questions';
import { useAtomValue } from 'jotai';
import { walletUtilsAtom } from 'store/app';
import { rpcUtilsAtom, walletUtilsAtom } from 'store/app';

interface Props {}

Expand Down Expand Up @@ -90,6 +90,7 @@ function VoteOnQuestions(props: {

export default function VotePanel(_props: Props) {
const walletUtils = useAtomValue(walletUtilsAtom);
const rpcUtils = useAtomValue(rpcUtilsAtom);
const { data, status } = usePublishedDatum(
walletUtils
? `wallet.${walletUtils.getWalletAddress()}.current`
Expand All @@ -98,8 +99,12 @@ export default function VotePanel(_props: Props) {
const { status: instanceStatus, data: instance } = usePublishedDatum(
'agoricNames.instance',
);

const invitationStatus = inferInvitationStatus(status, data, 'Voter');
const invitationStatus = inferInvitationStatus(
status,
data,
'Voter',
rpcUtils?.agoricNames.instance.economicCommittee,
);
const previousOfferId = invitationStatus.acceptedIn;

return (
Expand Down
13 changes: 8 additions & 5 deletions src/lib/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ export const inferInvitationStatus = (
status: LoadStatus,
current: CurrentWalletRecord | undefined,
descriptionSubstr: string,
contractInstance,
) => {
if (status === LoadStatus.Idle) {
return { status: 'idle' };
Expand All @@ -440,24 +441,26 @@ export const inferInvitationStatus = (
// first check for accepted
const usedInvitationEntry = coerceEntries(current.offerToUsedInvitation).find(
([_, invitationAmount]) =>
invitationAmount.value[0].description.includes(descriptionSubstr),
invitationAmount.value[0].description.includes(descriptionSubstr) &&
invitationAmount.value[0].instance === contractInstance,
);
if (usedInvitationEntry) {
return {
status: 'accepted',
acceptedIn: usedInvitationEntry[0],
};
}
// if that's not available, see if there's an invitation that can be used

// if that's not available, see if there's an invitation that can be used
const invitationPurse = current.purses.find(p => {
// xxx take this as param
return p.brand.toString().includes('Invitation');
});

const invitation: Amount<'set'> | undefined =
invitationPurse.balance.value.find(a =>
a.description.includes(descriptionSubstr),
invitationPurse.balance.value.find(
a =>
a.description.includes(descriptionSubstr) &&
a.instance === contractInstance,
);
if (invitation) {
return {
Expand Down

0 comments on commit 0128fd0

Please sign in to comment.