Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
obany committed Mar 25, 2021
2 parents 89b405b + df71d40 commit 1ea7838
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/app/components/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class Wallet extends Component<WalletProps, WalletState> {
<th>Color</th>
<th>Confirmed</th>
<th>Pending</th>
<th>Rejected</th>
<th>&nbsp;</th>
</tr>
</thead>
Expand All @@ -233,6 +234,9 @@ class Wallet extends Component<WalletProps, WalletState> {
<td className="warning">
{balance.unConfirmed.toString()}
</td>
<td className="danger">
{balance.rejected.toString()}
</td>
<td>
<button
disabled={balance.confirmed <= 0}
Expand Down
7 changes: 6 additions & 1 deletion src/iota/api/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ export class ApiClient {
if (!fetchResponse) {
throw new Error("No data was returned from the API");
} else {
response = await fetchResponse.json();
try {
response = await fetchResponse.json();
} catch (err) {
const text = await fetchResponse.text();
throw new Error(err.message + " --- " + text);
}
if (!fetchResponse.ok) {
if (response.error) {
throw new Error(response.error);
Expand Down
5 changes: 5 additions & 0 deletions src/models/IWalletBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ export interface IWalletBalance {
* Unconfirmed Balance.
*/
unConfirmed: bigint;

/**
* Rejected Balance.
*/
rejected: bigint;
}
22 changes: 13 additions & 9 deletions src/services/walletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,11 @@ export class WalletService implements IWalletService {
const aManaPledgeBytes = Base58.decode(aManaPledge);
if (aManaPledgeBytes.length !== 32) {
throw new Error("accessManaPledgeID is not valid");
return undefined;
}

const cManaPledgeBytes = Base58.decode(cManaPledge);
if (cManaPledgeBytes.length !== 32) {
throw new Error("consensusManaPledgeID is not valid");
return undefined;
}

const version = 0;
Expand Down Expand Up @@ -338,7 +336,7 @@ export class WalletService implements IWalletService {
for (const index in inputs) {
const addr = this._addresses.find(a => a.address === addressByOutputID[inputs[index]]);
if (addr) {
if (existingUnlockBlocks[addr.address]) {
if (existingUnlockBlocks[addr.address] !== undefined) {
unlockBlocks.push({type:1, referenceIndex:existingUnlockBlocks[addr.address], publicKey: Buffer.alloc(0), signature: Buffer.alloc(0) });
continue;
}
Expand Down Expand Up @@ -510,11 +508,14 @@ export class WalletService implements IWalletService {
if (this._unspentOutputs) {
for (const unspentOutput of this._unspentOutputs) {
let outputsFromAddressSpent = false;


const confirmedUnspentOutputs = unspentOutput.outputs.filter(o =>
(!this._spentOutputTransactions ||
!this._spentOutputTransactions.includes(o.id)) &&
o.inclusionState.confirmed);

// scan the outputs on this address for required funds
for (const output of unspentOutput.outputs.filter(o =>
!this._spentOutputTransactions ||
!this._spentOutputTransactions.includes(o.id))) {
for (const output of confirmedUnspentOutputs) {
// keeps track if the output contains any usable funds
let requiredColorFoundInOutput = false;

Expand Down Expand Up @@ -544,7 +545,7 @@ export class WalletService implements IWalletService {
// if outputs from this address were spent add the remaining outputs as well
// (we want to spend only once from every address if we are not using a reusable address)
if (outputsFromAddressSpent && !this._reusableAddresses) {
for (const output of unspentOutput.outputs) {
for (const output of confirmedUnspentOutputs) {
outputsToConsume[unspentOutput.address][output.id] = output;
}
}
Expand Down Expand Up @@ -810,12 +811,15 @@ export class WalletService implements IWalletService {
colorMap[balance.color] = {
asset: assetsMap[balance.color],
confirmed: BigInt(0),
unConfirmed: BigInt(0)
unConfirmed: BigInt(0),
rejected: BigInt(0)
};
this._balances.push(colorMap[balance.color]);
}
if (output.inclusionState.confirmed) {
colorMap[balance.color].confirmed += balance.value;
} else if (output.inclusionState.rejected) {
colorMap[balance.color].rejected += balance.value;
} else {
colorMap[balance.color].unConfirmed += balance.value;
}
Expand Down

0 comments on commit 1ea7838

Please sign in to comment.