Skip to content

Commit

Permalink
chore: fix leftover stakingProgram references
Browse files Browse the repository at this point in the history
  • Loading branch information
truemiller committed Sep 11, 2024
1 parent 8fa398a commit af89188
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
11 changes: 6 additions & 5 deletions frontend/components/MainPage/header/AgentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,16 @@ const AgentNotRunningButton = () => {
} = useBalance();
const { storeState } = useStore();
const { isEligibleForStaking, isAgentEvicted } = useStakingContractInfo();
const { activeStakingProgramId: activeStakingProgram, defaultStakingProgramId: defaultStakingProgram } = useStakingProgram();
const { activeStakingProgramId, defaultStakingProgramId } =
useStakingProgram();

// const minStakingDeposit =
// stakingContractInfoRecord?.[activeStakingProgram ?? defaultStakingProgram]
// ?.minStakingDeposit;

const requiredOlas = getMinimumStakedAmountRequired(
serviceTemplate,
activeStakingProgram ?? defaultStakingProgram,
activeStakingProgramId ?? defaultStakingProgramId,
);

const safeOlasBalance = safeBalance?.OLAS;
Expand Down Expand Up @@ -154,7 +155,7 @@ const AgentNotRunningButton = () => {
// Then create / deploy the service
try {
await ServicesService.createService({
stakingProgramId: activeStakingProgram ?? defaultStakingProgram, // overwrite with StakingProgram.Alpha to test migration
stakingProgramId: activeStakingProgramId ?? defaultStakingProgramId, // overwrite with StakingProgram.Alpha to test migration
serviceTemplate,
deploy: true,
});
Expand Down Expand Up @@ -187,8 +188,8 @@ const AgentNotRunningButton = () => {
setServiceStatus,
masterSafeAddress,
showNotification,
activeStakingProgram,
defaultStakingProgram,
activeStakingProgramId,
defaultStakingProgramId,
serviceTemplate,
]);

Expand Down
6 changes: 3 additions & 3 deletions frontend/components/MainPage/modals/MigrationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export const MigrationSuccessModal = ({
open: boolean;
onClose: () => void;
}) => {
const { activeStakingProgramId: activeStakingProgram } = useStakingProgram();
const { activeStakingProgramId } = useStakingProgram();

// Close modal if no active staking program, migration doesn't apply to non-stakers
if (!activeStakingProgram) {
if (!activeStakingProgramId) {
onClose();
return null;
}

const activeStakingProgramMeta = STAKING_PROGRAM_META[activeStakingProgram];
const activeStakingProgramMeta = STAKING_PROGRAM_META[activeStakingProgramId];

return (
<Modal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const MigrateButton = ({ stakingProgramId }: MigrateButtonProps) => {
goto(Pages.Main);

await ServicesService.createService({
stakingProgramId: stakingProgramId,
stakingProgramId,
serviceTemplate,
deploy: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const { useToken } = theme;

type StakingContractSectionProps = { stakingProgramId: StakingProgramId };
export const StakingContractSection = ({
stakingProgramId: stakingProgramId,
stakingProgramId,
}: StakingContractSectionProps) => {
const { activeStakingProgramId, defaultStakingProgramId } =
useStakingProgram();
Expand Down
30 changes: 15 additions & 15 deletions frontend/components/ManageStakingPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ import { WhatAreStakingContractsSection } from './WhatAreStakingContracts';

export const ManageStakingPage = () => {
const { goto } = usePageState();
const { activeStakingProgramId: activeStakingProgram } = useStakingProgram();
const { activeStakingProgramId } = useStakingProgram();

const orderedStakingPrograms: StakingProgramId[] = Object.values(
const orderedStakingProgramIds: StakingProgramId[] = Object.values(
StakingProgramId,
).reduce((acc: StakingProgramId[], stakingProgram: StakingProgramId) => {
).reduce((acc: StakingProgramId[], stakingProgramId: StakingProgramId) => {
// put the active staking program at the top
if (stakingProgram === activeStakingProgram) {
return [stakingProgram, ...acc];
if (stakingProgramId === activeStakingProgramId) {
return [stakingProgramId, ...acc];
}

// otherwise, append to the end
return [...acc, stakingProgram];
return [...acc, stakingProgramId];
}, []);

const otherStakingPrograms = orderedStakingPrograms.filter(
(stakingProgram) => {
const info = STAKING_PROGRAM_META[stakingProgram];
const otherStakingProgramIds = orderedStakingProgramIds.filter(
(stakingProgramId) => {
const info = STAKING_PROGRAM_META[stakingProgramId];
if (!info) return false;
if (activeStakingProgram === stakingProgram) return false;
if (activeStakingProgramId === stakingProgramId) return false;
if (info.deprecated) return false;
return true;
},
Expand All @@ -51,16 +51,16 @@ export const ManageStakingPage = () => {
}
>
<WhatAreStakingContractsSection />
<StakingContractSection stakingProgramId={orderedStakingPrograms[0]} />
<StakingContractSection stakingProgramId={orderedStakingProgramIds[0]} />

<CardSection borderbottom="true" vertical gap={16}>
{`Browse ${otherStakingPrograms.length} staking contract${otherStakingPrograms.length > 1 ? 's' : ''}.`}
{`Browse ${otherStakingProgramIds.length} staking contract${otherStakingProgramIds.length > 1 ? 's' : ''}.`}
</CardSection>

{otherStakingPrograms.map((stakingProgram) => (
{otherStakingProgramIds.map((stakingProgramId) => (
<StakingContractSection
key={stakingProgram}
stakingProgramId={stakingProgram}
key={stakingProgramId}
stakingProgramId={stakingProgramId}
/>
))}
</Card>
Expand Down
4 changes: 2 additions & 2 deletions frontend/service/Services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const getServices = async (): Promise<Service[]> =>
const createService = async ({
deploy,
serviceTemplate,
stakingProgramId: stakingProgram,
stakingProgramId,
}: {
deploy: boolean;
serviceTemplate: ServiceTemplate;
Expand All @@ -47,7 +47,7 @@ const createService = async ({
configurations: {
100: {
...serviceTemplate.configurations[100],
staking_program_id: stakingProgram,
staking_program_id: stakingProgramId,
rpc: `${process.env.GNOSIS_RPC}`,
},
},
Expand Down

0 comments on commit af89188

Please sign in to comment.