Skip to content

Commit

Permalink
Minor make check fixes. linter ran
Browse files Browse the repository at this point in the history
  • Loading branch information
eviterin committed Mar 26, 2024
1 parent 206e188 commit 770e28d
Show file tree
Hide file tree
Showing 8 changed files with 493 additions and 503 deletions.
9 changes: 2 additions & 7 deletions packages/contracts/src/Inventory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,10 @@ contract Inventory is Ownable {
// ---------------------------------------------------------------------------------------------

// Returns the list of cards in the given deck of the given player.
function getDeck(address player, uint8 deckID)
external
view
exists(player, deckID)
returns (Deck memory)
{
function getDeck(address player, uint8 deckID) external view exists(player, deckID) returns (Deck memory) {
return decks[player][deckID];
}

// ---------------------------------------------------------------------------------------------

// Returns the decks of a given player.
Expand Down
316 changes: 158 additions & 158 deletions packages/webapp/src/actions/getDeck.ts
Original file line number Diff line number Diff line change
@@ -1,158 +1,158 @@
import { defaultErrorHandling } from "src/actions/errors"
import { contractWriteThrowing } from "src/actions/libContractWrite"
import { Address } from "src/chain"
import { deployment } from "src/deployment"
import { inventoryABI } from "src/generated"

// =================================================================================================

export type GetDeckArgs = {
playerAddress: Address
onSuccess: () => void
}

export type GetDeckAtArgs = {
playerAddress: Address
onSuccess: () => void
index: number
}

// -------------------------------------------------------------------------------------------------

/**
* Fetches all decks of the given player by sending the `getAllDecks` transaction.
*
* Returns `true` iff the transaction is successful.
*/
export async function getAllDecks(args: GetDeckArgs): Promise<any> {
try {
return await getAllDecksImpl(args)
} catch (err) {
defaultErrorHandling("getAllDecks", err)
return false
}
}

/**
* Fetches the deck of the given player of a given ID by sending the `getDeck` transaction.
*
* Returns `true` iff the transaction is successful.
*/
export async function getDeck(args: GetDeckAtArgs): Promise<any> {
try {
return await getDeckImpl(args)
} catch (err) {
defaultErrorHandling("getDeck", err)
return false
}
}

// -------------------------------------------------------------------------------------------------

/**
* Fetches deck count of the given player by sending the `getNumDecks` transaction.
*
* Returns `true` iff the transaction is successful.
*/
export async function getNumDecks(args: GetDeckArgs): Promise<any> {
try {
return await getNumDecksImpl(args)
} catch (err) {
defaultErrorHandling("getNumDecks", err)
return false
}
}

// -------------------------------------------------------------------------------------------------

/**
* Fetches deck count of the given player by sending the `getNumDecks` transaction.
*
* Returns `true` iff the transaction is successful.
*/
export async function getDeckNames(args: GetDeckArgs): Promise<any> {
try {
return await getDeckNamesImpl(args)
} catch (err) {
defaultErrorHandling("getDeckNames", err)
return false
}
}

// -------------------------------------------------------------------------------------------------

async function getAllDecksImpl(args: GetDeckArgs): Promise<any> {
try {
const result = await contractWriteThrowing({
contract: deployment.Inventory,
abi: inventoryABI,
functionName: "getAllDecks",
args: [args.playerAddress],
})

args.onSuccess()
return result
} catch (error) {
console.error("Error fetching decks:", error)
return null
}
}

// -------------------------------------------------------------------------------------------------

async function getDeckImpl(args: GetDeckAtArgs): Promise<any> {
try {
const result = await contractWriteThrowing({
contract: deployment.Inventory,
abi: inventoryABI,
functionName: "getDeck",
args: [args.playerAddress, args.index],
})

args.onSuccess()
return result
} catch (error) {
console.error("Error fetching deck:", error)
return null
}
}

// -------------------------------------------------------------------------------------------------

async function getNumDecksImpl(args: GetDeckArgs): Promise<any> {
try {
const result = await contractWriteThrowing({
contract: deployment.Inventory,
abi: inventoryABI,
functionName: "getNumDecks",
args: [args.playerAddress],
})

args.onSuccess()
return result
} catch (error) {
console.error("Error fetching decks:", error)
return null
}
}

// -------------------------------------------------------------------------------------------------

async function getDeckNamesImpl(args: GetDeckArgs): Promise<any> {
try {
const result = await contractWriteThrowing({
contract: deployment.Inventory,
abi: inventoryABI,
functionName: "getDeckNames",
args: [args.playerAddress],
})

args.onSuccess()
return result
} catch (error) {
console.error("Error fetching decks:", error)
return null
}
}

// =================================================================================================
import { defaultErrorHandling } from "src/actions/errors"
import { contractWriteThrowing } from "src/actions/libContractWrite"
import { Address } from "src/chain"
import { deployment } from "src/deployment"
import { inventoryABI } from "src/generated"

// =================================================================================================

export type GetDeckArgs = {
playerAddress: Address
onSuccess: () => void
}

export type GetDeckAtArgs = {
playerAddress: Address
onSuccess: () => void
index: number
}

// -------------------------------------------------------------------------------------------------

/**
* Fetches all decks of the given player by sending the `getAllDecks` transaction.
*
* Returns `true` iff the transaction is successful.
*/
export async function getAllDecks(args: GetDeckArgs): Promise<any> {
try {
return await getAllDecksImpl(args)
} catch (err) {
defaultErrorHandling("getAllDecks", err)
return false
}
}

/**
* Fetches the deck of the given player of a given ID by sending the `getDeck` transaction.
*
* Returns `true` iff the transaction is successful.
*/
export async function getDeck(args: GetDeckAtArgs): Promise<any> {
try {
return await getDeckImpl(args)
} catch (err) {
defaultErrorHandling("getDeck", err)
return false
}
}

// -------------------------------------------------------------------------------------------------

/**
* Fetches deck count of the given player by sending the `getNumDecks` transaction.
*
* Returns `true` iff the transaction is successful.
*/
export async function getNumDecks(args: GetDeckArgs): Promise<any> {
try {
return await getNumDecksImpl(args)
} catch (err) {
defaultErrorHandling("getNumDecks", err)
return false
}
}

// -------------------------------------------------------------------------------------------------

/**
* Fetches deck count of the given player by sending the `getNumDecks` transaction.
*
* Returns `true` iff the transaction is successful.
*/
export async function getDeckNames(args: GetDeckArgs): Promise<any> {
try {
return await getDeckNamesImpl(args)
} catch (err) {
defaultErrorHandling("getDeckNames", err)
return false
}
}

// -------------------------------------------------------------------------------------------------

async function getAllDecksImpl(args: GetDeckArgs): Promise<any> {
try {
const result = await contractWriteThrowing({
contract: deployment.Inventory,
abi: inventoryABI,
functionName: "getAllDecks",
args: [args.playerAddress],
})

args.onSuccess()
return result
} catch (error) {
console.error("Error fetching decks:", error)
return null
}
}

// -------------------------------------------------------------------------------------------------

async function getDeckImpl(args: GetDeckAtArgs): Promise<any> {
try {
const result = await contractWriteThrowing({
contract: deployment.Inventory,
abi: inventoryABI,
functionName: "getDeck",
args: [args.playerAddress, args.index],
})

args.onSuccess()
return result
} catch (error) {
console.error("Error fetching deck:", error)
return null
}
}

// -------------------------------------------------------------------------------------------------

async function getNumDecksImpl(args: GetDeckArgs): Promise<any> {
try {
const result = await contractWriteThrowing({
contract: deployment.Inventory,
abi: inventoryABI,
functionName: "getNumDecks",
args: [args.playerAddress],
})

args.onSuccess()
return result
} catch (error) {
console.error("Error fetching decks:", error)
return null
}
}

// -------------------------------------------------------------------------------------------------

async function getDeckNamesImpl(args: GetDeckArgs): Promise<any> {
try {
const result = await contractWriteThrowing({
contract: deployment.Inventory,
abi: inventoryABI,
functionName: "getDeckNames",
args: [args.playerAddress],
})

args.onSuccess()
return result
} catch (error) {
console.error("Error fetching decks:", error)
return null
}
}

// =================================================================================================
3 changes: 2 additions & 1 deletion packages/webapp/src/actions/joinGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ async function joinGameImpl(args: JoinGameArgs): Promise<boolean> {
if (gameStatus < GameStatus.JOINED) {
// we can skip the join step if already performed
const promise = doJoinGameTransaction(args, privateInfo.saltHash)
if (gameID === null) await promise // gameID starts null and the call will set it
if (gameID === null)
await promise // gameID starts null and the call will set it
else checkFresh(await freshWrap(promise))
}

Expand Down
Loading

0 comments on commit 770e28d

Please sign in to comment.