Skip to content

Commit

Permalink
Fix account transactions history
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzandrock committed Mar 19, 2020
1 parent 5bf340d commit d0dd685
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 105 deletions.
6 changes: 4 additions & 2 deletions core/storage/src/chain/operations_ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl<'a> OperationsExtSchema<'a> {
on
tx_hash = hash
where
'0x:' || encode(primary_account_address, 'hex') = '{address}'
tx->>'from' = '{address}'
or
tx->>'to' = '{address}'
union all
Expand All @@ -316,7 +316,9 @@ impl<'a> OperationsExtSchema<'a> {
from
executed_priority_operations
where
operation->'priority_op'->>'from' = '{address}') t
operation->'priority_op'->>'from' = '{address}'
or
operation->'priority_op'->>'to' = '{address}') t
order by
block_number desc
offset
Expand Down
100 changes: 44 additions & 56 deletions js/client/src/WalletDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,22 @@ export class WalletDecorator {

// #region renderable
async transactionsAsRenderableList(offset, limit) {
if (!this.address) {
console.log(this.address);
const address = this.address;
if (!address) {
console.log(address);
return [];
}
let transactions = await this.blockExplorerClient.getAccountTransactions(this.address, offset, limit);
let res = transactions.map(async (tx, index) => {
let elem_id = `history_${index}`;
let type = tx.tx.type || '';
let hash = tx.hash;
let direction =
(type == 'Deposit') || (type == 'Transfer' && tx.tx.to == this.address)
const transactions = await this.blockExplorerClient.getAccountTransactions(address, offset, limit);
const res = transactions.map(async (tx, index) => {
const elem_id = `history_${index}`;
const type = tx.tx.type || '';
const hash = tx.hash;

const receiver_address = type == 'Deposit'
? tx.tx.priority_op.to
: tx.tx.to;

const direction = receiver_address == address
? 'incoming'
: 'outcoming';

Expand All @@ -181,104 +186,87 @@ export class WalletDecorator {
// pub commited: bool,
// pub verified: bool,

let status
const status
= tx.verified ? `<span style="color: green">(verified)</span>`
: tx.success == null ? `<span style="color: grey">(pending)</span>`
: tx.success == true ? `<span style="color: grey">(succeeded)</span>`
: tx.commited ? `<span style="color: grey">(committed)</span>`
: tx.fail_reason != null ? `<span style="color: red">(failed)</span>`
: `<span style="color: red">(Unknown status)</span>`;

let row_status
const row_status
= tx.verified ? `<span style="color: green">Verified</span>`
: tx.commited ? `<span style="color: grey">Committed</span>`
: tx.fail_reason ? `<span style="color: red">Failed with ${tx.fail_reason}</span>`
: `<span style="color: red">(Unknown status)</span>`
: `<span style="color: red">(Unknown status)</span>`;

// here is common data to all tx types
let data = {
const data = {
elem_id,
type, direction,
status, row_status,
hash,
};

switch (true) {
case type == 'Deposit': {
let token = this.tokenNameFromId(tx.tx.priority_op.token);
let amount = isReadablyPrintable(token)
? readableEther(tx.tx.priority_op.amount)
: utils.bigNumberify(tx.tx.priority_op.amount);
const token = await this.tokenNameFromId(tx.tx.priority_op.token);
const amount = readableEther(tx.tx.priority_op.amount);
return {
fields: [
{ key: 'amount', label: 'Amount' },
{ key: 'row_status', label: 'Status' },
{ key: 'pq_id', label: 'Priority op' },
],
data: Object.assign(data, {
data: {
...data,
from: tx.tx.priority_op.from,
to: tx.tx.priority_op.to,
pq_id: tx.pq_id,
token, amount,
}),
},
};
}
case type == 'Transfer' && direction == 'incoming': {
let token = this.tokenNameFromId(tx.tx.token);
let amount = isReadablyPrintable(token)
? readableEther(tx.tx.amount)
: utils.bigNumberify(tx.tx.amount);
return {
fields: [
{ key: 'amount', label: 'Amount' },
{ key: 'from', label: 'From' },
{ key: 'row_status', label: 'Status' },
{ key: 'hash', label: 'Tx hash' },
],
data: Object.assign(data, {
from: tx.tx.from,
token, amount,
hash: tx.hash,
}),
}
}
case type == 'Transfer' && direction == 'outcoming': {
let token = this.tokenNameFromId(tx.tx.token);
let amount = isReadablyPrintable(token)
? readableEther(tx.tx.amount)
: utils.bigNumberify(tx.tx.amount);
case type == 'Transfer': {
const token = await this.tokenNameFromId(tx.tx.token);
const amount = readableEther(tx.tx.amount);
return {
fields: [
{ key: 'amount', label: 'Amount' },
{ key: 'to', label: 'To' },
{ key: 'row_status', label: 'Status' },
{ key: 'hash', label: 'Tx hash' },
],
data: Object.assign(data, {
data: {
...data,
from: tx.tx.from,
to: tx.tx.to,
token, amount,
hash: tx.hash,
}),
}
},
};
}
case type == 'Withdraw': {
let token = this.tokenNameFromId(tx.tx.token);
let amount = isReadablyPrintable(token)
? readableEther(tx.tx.amount)
: utils.bigNumberify(tx.tx.amount);
const token = await this.tokenNameFromId(tx.tx.token);
const amount = readableEther(tx.tx.amount);
return {
fields: [
{ key: 'amount', label: 'Amount' },
{ key: 'row_status', label: 'Status' },
{ key: 'hash', label: 'Tx hash' },
],
data: Object.assign(data, {
data: {
...data,
from: tx.tx.from,
to: tx.tx.to,
token, amount,
hash: tx.hash,
}),
}
},
};
}
}
});

return await Promise.all(res);
const txs = await Promise.all(res);
return txs.filter(Boolean);
}
setPendingWithdrawStatus(withdrawTokenId, status) {
let withdrawsStatusesDict = JSON.parse(localStorage.getItem('withdrawsStatusesDict') || "{}");
Expand Down
4 changes: 2 additions & 2 deletions js/client/src/components/BalancesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</template>
<template v-slot:cell(amount)="data">
<span style="vertical-align: middle;"> {{ data.item.amount }} </span>
<CompleteOperationButton
<!-- <CompleteOperationButton
v-if="data.item.op && data.item.op.status != 'hidden'"
:op="data.item.op"
v-on:withdrawOnchainEvent="withdrawOnchainEvent"
></CompleteOperationButton>
></CompleteOperationButton> -->
</template>
</b-table>
<span v-if="disabledReason == 'ETH or FAU missing'">
Expand Down
78 changes: 33 additions & 45 deletions js/explorer/src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,17 @@ export class Client {
console.log(address);
return [];
}
let transactions = await this.blockExplorerClient.getAccountTransactions(address, offset, limit);
let res = transactions.map(async (tx, index) => {
let elem_id = `history_${index}`;
let type = tx.tx.type || '';
let hash = tx.hash;
let direction =
(type == 'Deposit') || (type == 'Transfer' && tx.tx.to == address)
const transactions = await this.blockExplorerClient.getAccountTransactions(address, offset, limit);
const res = transactions.map(async (tx, index) => {
const elem_id = `history_${index}`;
const type = tx.tx.type || '';
const hash = tx.hash;

const receiver_address = type == 'Deposit'
? tx.tx.priority_op.to
: tx.tx.to;

const direction = receiver_address == address
? 'incoming'
: 'outcoming';

Expand All @@ -157,103 +161,87 @@ export class Client {
// pub commited: bool,
// pub verified: bool,

let status
const status
= tx.verified ? `<span style="color: green">(verified)</span>`
: tx.success == null ? `<span style="color: grey">(pending)</span>`
: tx.success == true ? `<span style="color: grey">(succeeded)</span>`
: tx.commited ? `<span style="color: grey">(committed)</span>`
: tx.fail_reason != null ? `<span style="color: red">(failed)</span>`
: `<span style="color: red">(Unknown status)</span>`;

let row_status
const row_status
= tx.verified ? `<span style="color: green">Verified</span>`
: tx.commited ? `<span style="color: grey">Committed</span>`
: tx.fail_reason ? `<span style="color: red">Failed with ${tx.fail_reason}</span>`
: `<span style="color: red">(Unknown status)</span>`;

// here is common data to all tx types
let data = {
const data = {
elem_id,
type, direction,
status, row_status,
hash,
};

switch (true) {
case type == 'Deposit': {
let token = await this.tokenNameFromId(tx.tx.priority_op.token);
let amount = readableEther(tx.tx.priority_op.amount);
const token = await this.tokenNameFromId(tx.tx.priority_op.token);
const amount = readableEther(tx.tx.priority_op.amount);
return {
fields: [
{ key: 'amount', label: 'Amount' },
{ key: 'row_status', label: 'Status' },
{ key: 'pq_id', label: 'Priority op' },
],
data: Object.assign(data, {
data: {
...data,
from: tx.tx.priority_op.from,
to: tx.tx.priority_op.to,
pq_id: tx.pq_id,
token, amount,
hash,
}),
};
}
case type == 'Transfer' && direction == 'incoming': {
let token = await this.tokenNameFromId(tx.tx.token);
let amount = readableEther(tx.tx.amount);
return {
fields: [
{ key: 'amount', label: 'Amount' },
{ key: 'from', label: 'From' },
{ key: 'row_status', label: 'Status' },
{ key: 'hash', label: 'Tx hash' },
],
data: Object.assign(data, {
from: tx.tx.from,
to: tx.tx.to,
token, amount,
hash: tx.hash,
}),
},
};
}
case type == 'Transfer' && direction == 'outcoming': {
let token = await this.tokenNameFromId(tx.tx.token);
let amount = readableEther(tx.tx.amount);
case type == 'Transfer': {
const token = await this.tokenNameFromId(tx.tx.token);
const amount = readableEther(tx.tx.amount);
return {
fields: [
{ key: 'amount', label: 'Amount' },
{ key: 'to', label: 'To' },
{ key: 'row_status', label: 'Status' },
{ key: 'hash', label: 'Tx hash' },
],
data: Object.assign(data, {
data: {
...data,
from: tx.tx.from,
to: tx.tx.to,
token, amount,
hash: tx.hash,
}),
},
};
}
case type == 'Withdraw': {
let token = await this.tokenNameFromId(tx.tx.token);
let amount = readableEther(tx.tx.amount);
const token = await this.tokenNameFromId(tx.tx.token);
const amount = readableEther(tx.tx.amount);
return {
fields: [
{ key: 'amount', label: 'Amount' },
{ key: 'row_status', label: 'Status' },
{ key: 'hash', label: 'Tx hash' },
],
data: Object.assign(data, {
data: {
...data,
from: tx.tx.from,
to: tx.tx.to,
token, amount,
hash: tx.hash,
}),
},
};
}
}
});

return await Promise.all(res);
const txs = await Promise.all(res);
return txs.filter(Boolean);
}
};

Expand Down

0 comments on commit d0dd685

Please sign in to comment.