Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
refactor: overall latest transactions per profile (#1034)
Browse files Browse the repository at this point in the history
  • Loading branch information
dated authored and j-a-m-l committed Jan 30, 2019
1 parent 683a76d commit 90a6251
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 27 deletions.
6 changes: 3 additions & 3 deletions __tests__/unit/services/client.spec.js
Expand Up @@ -514,7 +514,7 @@ describe('Services > Client', () => {
expect(transaction).not.toHaveProperty('senderId')
expect(transaction).not.toHaveProperty('recipientId')
expect(transaction).not.toHaveProperty('isSender')
expect(transaction).not.toHaveProperty('isReceiver')
expect(transaction).not.toHaveProperty('isRecipient')
})
})
})
Expand Down Expand Up @@ -550,7 +550,7 @@ describe('Services > Client', () => {
expect(transaction).toHaveProperty('totalAmount', data[i].amount + data[i].fee)
expect(transaction).toHaveProperty('timestamp', new Date(data[i].timestamp.human).getTime())
expect(transaction).toHaveProperty('isSender')
expect(transaction).toHaveProperty('isReceiver')
expect(transaction).toHaveProperty('isRecipient')
expect(transaction).toHaveProperty('sender')
expect(transaction).toHaveProperty('recipient')
expect(transaction).not.toHaveProperty('senderId')
Expand Down Expand Up @@ -587,7 +587,7 @@ describe('Services > Client', () => {
expect(transaction).toHaveProperty('totalAmount', data[i].amount + data[i].fee)
expect(transaction).toHaveProperty('timestamp', data[i].timestamp.unix * 1000)
expect(transaction).toHaveProperty('isSender')
expect(transaction).toHaveProperty('isReceiver')
expect(transaction).toHaveProperty('isRecipient')
expect(transaction).toHaveProperty('sender')
expect(transaction).toHaveProperty('recipient')
expect(transaction).not.toHaveProperty('senderId')
Expand Down
8 changes: 4 additions & 4 deletions __tests__/unit/store/modules/transaction.spec.js
Expand Up @@ -74,7 +74,7 @@ describe('TransactionModule', () => {
transactions.forEach(transaction => {
expect(transaction).toHaveProperty('totalAmount')
expect(transaction).toHaveProperty('isSender')
expect(transaction).toHaveProperty('isReceiver', true)
expect(transaction).toHaveProperty('isRecipient', true)
})
})
})
Expand All @@ -90,7 +90,7 @@ describe('TransactionModule', () => {
transactions.forEach(transaction => {
expect(transaction).toHaveProperty('totalAmount')
expect(transaction).toHaveProperty('isSender', true)
expect(transaction).toHaveProperty('isReceiver')
expect(transaction).toHaveProperty('isRecipient')
})
})
})
Expand All @@ -107,7 +107,7 @@ describe('TransactionModule', () => {
transactions.forEach(transaction => {
expect(transaction).toHaveProperty('totalAmount')
expect(transaction).toHaveProperty('isSender', transaction.sender === 'A3')
expect(transaction).toHaveProperty('isReceiver', transaction.recipient === 'A3')
expect(transaction).toHaveProperty('isRecipient', transaction.recipient === 'A3')
})
})
})
Expand All @@ -134,7 +134,7 @@ describe('TransactionModule', () => {
transactions.forEach(transaction => {
expect(transaction).toHaveProperty('totalAmount')
expect(transaction).toHaveProperty('isSender')
expect(transaction).toHaveProperty('isReceiver')
expect(transaction).toHaveProperty('isRecipient')
})
})
})
Expand Down
27 changes: 13 additions & 14 deletions src/renderer/components/Dashboard/DashboardTransactions.vue
Expand Up @@ -3,11 +3,12 @@
:has-short-id="true"
:rows="lastTransactions"
:is-dashboard="true"
:is-loading="isLoading"
/>
</template>

<script>
import { uniqBy } from 'lodash'
import { uniqBy, orderBy, flatten } from 'lodash'
import mergeTableTransactions from '@/components/utils/merge-table-transactions'
import { TransactionTable } from '@/components/Transaction'
Expand All @@ -22,13 +23,14 @@ export default {
numberOfTransactions: {
type: Number,
required: false,
default: 10
default: 50
}
},
data: () => ({
fetchedTransactions: [],
previousWalletAddresses: []
previousWalletAddresses: [],
isLoading: false
}),
computed: {
Expand Down Expand Up @@ -71,6 +73,9 @@ export default {
methods: {
async fetchTransactions (updatePreviousWallets = true) {
if (!this.fetchedTransactions.length) {
this.isLoading = true
}
if (!this.wallets.length) {
return
}
Expand All @@ -81,23 +86,17 @@ export default {
try {
const addresses = this.wallets.map(wallet => wallet.address)
const walletTransactions = await this.$client.fetchTransactionsForWallets(addresses)
for (const transactions of Object.values(walletTransactions)) {
this.$set(this, 'fetchedTransactions', uniqBy([
/*
* NOTE: The order of this 2 lines is VERY important:
* recent transactions should override older to have the up-to-date number of confirmations
*/
...transactions.slice(0, this.numberOfTransactions),
...this.fetchedTransactions
], 'id'))
}
const transactions = await this.$client.fetchTransactionsForWallets(addresses)
const ordered = orderBy(uniqBy(flatten(Object.values(transactions)), 'id'), 'timestamp', 'desc')
this.fetchedTransactions = ordered.slice(0, this.numberOfTransactions)
} catch (error) {
this.$logger.error(error)
this.$error(this.$t('COMMON.FAILED_FETCH', {
name: 'transactions',
msg: error.message
}))
} finally {
this.isLoading = false
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Transaction/TransactionAmount.vue
Expand Up @@ -2,7 +2,7 @@
<span
:class="{
'text-red': transaction.isSender && transaction.amount,
'text-green': transaction.isReceiver && isTransfer,
'text-green': transaction.isRecipient && isTransfer,
}"
>
{{ formatter_networkCurrency(transaction.amount) }}
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/pages/Dashboard.vue
Expand Up @@ -11,10 +11,13 @@
</div>

<div class="p-10">
<div class="text-lg font-semibold mb-4">
<h3 class="flex items-center">
{{ $t('PAGES.DASHBOARD.LAST_TRANSACTIONS') }}
</h3>

<div class="Dashboard__transactions">
<DashboardTransactions />
</div>
<DashboardTransactions />
</div>
</main>

Expand Down Expand Up @@ -91,6 +94,9 @@ export default {
</style>

<style lang="postcss" scoped>
.Dashboard__transactions {
@apply .mt-10;
}
.Dashboard__wallets__list {
border-top: 0.08rem solid var(--theme-feature-item-alternative);
}
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/services/client.js
Expand Up @@ -327,7 +327,7 @@ export default class ClientService {
// Add some utilities for each transactions
const result = transactions.map(tx => {
tx.isSender = tx.sender === address
tx.isReceiver = tx.recipient === address
tx.isRecipient = tx.recipient === address
tx.totalAmount = tx.amount + tx.fee

return tx
Expand Down Expand Up @@ -367,6 +367,8 @@ export default class ClientService {
if (!hadFailure) {
transactions = orderBy(transactions, 'timestamp', 'desc').map(transaction => {
transaction.timestamp = transaction.timestamp.unix * 1000 // to milliseconds
transaction.isSender = addresses.includes(transaction.sender)
transaction.isRecipient = addresses.includes(transaction.recipient)

return transaction
})
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/store/modules/transaction.js
Expand Up @@ -32,7 +32,7 @@ export default {
return transaction.recipient === address || transaction.sender === address
}).map(transaction => {
transaction.isSender = transaction.sender === address
transaction.isReceiver = transaction.recipient === address
transaction.isRecipient = transaction.recipient === address
transaction.totalAmount = transaction.amount + transaction.fee

return transaction
Expand All @@ -56,7 +56,7 @@ export default {

const transactions = state.transactions[profileId].map(transaction => {
transaction.isSender = addresses.includes(transaction.sender)
transaction.isReceiver = addresses.includes(transaction.recipient)
transaction.isRecipient = addresses.includes(transaction.recipient)
transaction.totalAmount = transaction.amount + transaction.fee

return transaction
Expand Down

0 comments on commit 90a6251

Please sign in to comment.