Skip to content

Commit

Permalink
added TransactionStatus to send fleet
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Jan 2, 2024
1 parent c9ee099 commit b8a06b9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getFuelConsumption,
} from '../../shared/utils/FleetUtils';
import { convertSecondsToTime } from '../../shared/utils';
import { TransactionStatus } from '../ui/TransactionStatus';

type ShipName = 'carrier' | 'scraper' | 'sparrow' | 'frigate' | 'armade';

Expand Down Expand Up @@ -165,6 +166,8 @@ function ButtonAttackPlanet({
const [travelTime, setTravelTime] = useState(0);
const [fuelConsumption, setFuelConsumption] = useState(0);
const [cargoCapacity, setCargoCapacity] = useState(0);
const [isModalOpen, setIsModalOpen] = useState(false);
const [isButtotClicked, setisButtotClicked] = useState(false);

const missions = useGetActiveMissions(planetId);
const isMissionLimitReached =
Expand All @@ -179,8 +182,6 @@ function ButtonAttackPlanet({
0
);

const [isModalOpen, setIsModalOpen] = useState(false);

const handleButtonClick = () => {
setIsModalOpen(true);
};
Expand Down Expand Up @@ -216,7 +217,7 @@ function ButtonAttackPlanet({
setCargoCapacity(calculateTotalCargoCapacity(fleet));
}, [distance, fleet, ownPosition, techs]);

const { writeAsync } = useSendFleet(fleet, position, false);
const { writeAsync, data } = useSendFleet(fleet, position, false);

const ships = ['carrier', 'scraper', 'sparrow', 'frigate', 'armade'];

Expand All @@ -234,6 +235,10 @@ function ButtonAttackPlanet({
}
}, [travelTime]);

const handleSendClick = () => {
writeAsync(), setIsModalOpen(false), setisButtotClicked(true);
};

return (
<div>
{!disabled && !noRequirements && !isNoobProtected && (
Expand Down Expand Up @@ -359,7 +364,7 @@ function ButtonAttackPlanet({
</Text>
</WarningContainer>
<StyledButton
onClick={() => writeAsync()}
onClick={handleSendClick}
fullWidth
style={{
background: isAnyShipOverLimit ? '#3B3F53' : '#4A63AA',
Expand All @@ -370,6 +375,9 @@ function ButtonAttackPlanet({
</StyledButton>
</StyledBox>
</Modal>
{isButtotClicked && (
<TransactionStatus name="Sent Fleet" tx={data?.transaction_hash} />
)}
</>
)}
{!disabled && noRequirements && (
Expand Down
1 change: 1 addition & 0 deletions packages/testnet/frontend/src/components/ui/MissionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const MissionRow = memo(
}}
size="small"
sx={{ background: '#4A63AA' }}
fullWidth
>
{mission.is_debris ? 'Collect' : 'Attack'}
</StyledButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export default function useSendFleet(
abi: game.abi,
address: GAMEADDRESS,
});
const { writeAsync, isPending } = useContractWrite({
const { writeAsync, data } = useContractWrite({
calls: [
contract?.populateTransaction.send_fleet!(fleet, position, isDebris),
],
});

return { writeAsync, isPending };
return { writeAsync, data };
}

0 comments on commit b8a06b9

Please sign in to comment.