Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 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
5 changes: 4 additions & 1 deletion client/src/Backend/GameLogic/ContractsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,10 @@ export class ContractsAPI extends EventEmitter {
public async getPlayerById(playerId: EthAddress): Promise<Player | undefined> {
const rawPlayer = await this.makeCall(this.contract.players, [playerId]);
if (!rawPlayer.isInitialized) return undefined;
const player = decodePlayer(rawPlayer);
// This is horrible and unsustainable. We need some way to get Player + Silver token balance for
// bulk players as well.
const balance = await this.makeCall(this.contract.getSilverBalance, [playerId]);
const player = decodePlayer(rawPlayer, balance.toNumber());

return player;
}
Expand Down
14 changes: 3 additions & 11 deletions client/src/Backend/GameLogic/GameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,6 @@ class GameManager extends EventEmitter {

public async withdrawSilver(
locationId: LocationId,
amount: number,
bypassChecks = false
): Promise<Transaction<UnconfirmedWithdrawSilver>> {
try {
Expand All @@ -2442,21 +2441,15 @@ class GameManager extends EventEmitter {
if (!planet) {
throw new Error('tried to withdraw silver from an unknown planet');
}
if (planet.planetType !== PlanetType.TRADING_POST) {
throw new Error('can only withdraw silver from spacetime rips');
if (planet.planetType !== PlanetType.SILVER_MINE) {
throw new Error('can only withdraw silver from asteroid');
}
if (planet.owner !== this.account) {
throw new Error('can only withdraw silver from a planet you own');
}
if (planet.transactions?.hasTransaction(isUnconfirmedWithdrawSilverTx)) {
throw new Error('a withdraw silver action is already in progress for this planet');
}
if (amount > planet.silver) {
throw new Error('not enough silver to withdraw!');
}
if (amount === 0) {
throw new Error('must withdraw more than 0 silver!');
}
if (planet.destroyed) {
throw new Error("can't withdraw silver from a destroyed planet");
}
Expand All @@ -2467,9 +2460,8 @@ class GameManager extends EventEmitter {
const txIntent: UnconfirmedWithdrawSilver = {
methodName: 'withdrawSilver',
contract: this.contractsAPI.contract,
args: Promise.resolve([locationIdToDecStr(locationId), amount * CONTRACT_PRECISION]),
args: Promise.resolve([locationIdToDecStr(locationId)]),
locationId,
amount,
};

// Always await the submitTransaction so we can catch rejections
Expand Down
14 changes: 2 additions & 12 deletions client/src/Backend/GameLogic/GameUIManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,18 +397,8 @@ class GameUIManager extends EventEmitter {
this.gameManager.deactivateArtifact(locationId, artifactId);
}

public withdrawSilver(locationId: LocationId, amount: number) {
const dontShowWarningStorageKey = `${this.getAccount()?.toLowerCase()}-withdrawnWarningAcked`;

if (localStorage.getItem(dontShowWarningStorageKey) !== 'true') {
localStorage.setItem(dontShowWarningStorageKey, 'true');
const confirmationText =
`Are you sure you want withdraw this silver? Once you withdraw it, you ` +
`cannot deposit it again. Your withdrawn silver amount will be added to your score. You'll only see this warning once!`;
if (!confirm(confirmationText)) return;
}

this.gameManager.withdrawSilver(locationId, amount);
public withdrawSilver(locationId: LocationId) {
this.gameManager.withdrawSilver(locationId);
}

public startWormholeFrom(planet: LocatablePlanet): Promise<LocatablePlanet | undefined> {
Expand Down
2 changes: 1 addition & 1 deletion client/src/Frontend/Components/OpenPaneButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function OpenPlanetInfoButton({
return (
<OpenPaneButton
modal={modal}
title='Info'
title='More Info'
shortcut={TOGGLE_PLANET_INFO_PANE}
element={() => <PlanetInfoPane initialPlanetId={planetId} />}
helpContent={PlanetInfoHelpContent()}
Expand Down
11 changes: 1 addition & 10 deletions client/src/Frontend/Panes/PlanetContextPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { CapturePlanetButton } from '../Components/CapturePlanetButton';
import { VerticalSplit } from '../Components/CoreUI';
import { MineArtifactButton } from '../Components/MineArtifactButton';
import {
OpenBroadcastPaneButton,
OpenHatPaneButton,
OpenManagePlanetInventoryButton,
OpenPlanetInfoButton,
OpenUpgradeDetailsPaneButton,
Expand Down Expand Up @@ -53,15 +51,10 @@ function PlanetContextPaneContent({
}

let upgradeRow = null;
if (!p?.destroyed && owned) {
if (!p?.destroyed && owned && p?.planetType == PlanetType.PLANET) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!p?.destroyed && owned && p?.planetType == PlanetType.PLANET) {
if (!p?.destroyed && owned && p?.planetType === PlanetType.PLANET) {

upgradeRow = <OpenUpgradeDetailsPaneButton modal={modal} planetId={p?.locationId} />;
}

let hatRow = null;
if (!p?.destroyed && owned) {
hatRow = <OpenHatPaneButton modal={modal} planetId={p?.locationId} />;
}

let withdrawRow = null;
if (!p?.destroyed && owned && p?.planetType === PlanetType.TRADING_POST) {
withdrawRow = <WithdrawSilver wrapper={planet} />;
Expand All @@ -86,12 +79,10 @@ function PlanetContextPaneContent({
<VerticalSplit>
<>
{upgradeRow}
<OpenBroadcastPaneButton modal={modal} planetId={p?.locationId} />
<OpenPlanetInfoButton modal={modal} planetId={p?.locationId} />
</>
<>
<OpenManagePlanetInventoryButton modal={modal} planetId={p?.locationId} />
{hatRow}
</>
</VerticalSplit>
{withdrawRow}
Expand Down
1 change: 1 addition & 0 deletions client/src/Frontend/Utils/ShortcutConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const TOGGLE_TRANSACTIONS_PANE = "'";
export const TOGGLE_PLANET_INVENTORY_PANE = 's';
export const TOGGLE_HAT_PANE = 'x';
export const TOGGLE_ABANDON = 'r';
export const TOGGLE_WITHDRAW = ']';
export const INVADE = 'y';
export const MINE_ARTIFACT = 'f';
export const TOGGLE_BROADCAST_PANE = 'z';
Expand Down
33 changes: 20 additions & 13 deletions client/src/Frontend/Views/ArtifactRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,25 @@ export function SelectArtifactRow({
artifacts: Artifact[];
}) {
return (
<RowWrapper>
{artifacts.length > 0 &&
artifacts.map((a) => (
<span key={a.id}>
<ArtifactThumb
artifact={a}
selectedArtifact={selectedArtifact}
onArtifactChange={onArtifactChange}
/>
<Spacer width={4} />
</span>
))}
</RowWrapper>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
}}
>
<RowWrapper>
{artifacts.length > 0 &&
artifacts.map((a) => (
<span key={a.id}>
<ArtifactThumb
artifact={a}
selectedArtifact={selectedArtifact}
onArtifactChange={onArtifactChange}
/>
<Spacer width={4} />
</span>
))}
</RowWrapper>
</div>
);
}
Loading