Skip to content

Commit

Permalink
Fix wallets assignment bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tuler committed Oct 19, 2023
1 parent 5c7f59f commit 4189e2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-geckos-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@deroll/wallet": patch
---

fix wallets assignment bug
8 changes: 6 additions & 2 deletions packages/wallet/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export class WalletAppImpl implements WalletApp {

walletFrom.ether = walletFrom.ether - amount;
walletTo.ether = walletTo.ether + amount;
this.wallets[from] = walletFrom;
this.wallets[to] = walletTo;
}

transferERC20(
Expand Down Expand Up @@ -137,6 +139,8 @@ export class WalletAppImpl implements WalletApp {
walletTo.erc20[token] = walletTo.erc20[token]
? walletTo.erc20[token] + amount
: amount;
this.wallets[from] = walletFrom;
this.wallets[to] = walletTo;
}

withdrawEther(address: Address, amount: bigint): Voucher {
Expand All @@ -151,7 +155,7 @@ export class WalletAppImpl implements WalletApp {
}

// check balance
if (wallet.ether < amount) {
if (!wallet || wallet.ether < amount) {
throw new Error(
`insufficient balance of user ${address}: ${amount.toString()} > ${wallet.ether.toString()}`,
);
Expand Down Expand Up @@ -180,7 +184,7 @@ export class WalletAppImpl implements WalletApp {
const wallet = this.wallets[address];

// check balance
if (!wallet.erc20[token] || wallet.erc20[token] < amount) {
if (!wallet || !wallet.erc20[token] || wallet.erc20[token] < amount) {
throw new Error(
`insufficient balance of user ${address} of token ${token}: ${amount.toString()} > ${
wallet.erc20[token]?.toString() ?? "0"
Expand Down

0 comments on commit 4189e2a

Please sign in to comment.