Skip to content

Commit

Permalink
fix(webapp): update recategorize expend tool for the new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
warnerHurtado committed Jan 13, 2023
1 parent 2bbeb84 commit 3c32038
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 128 deletions.
1 change: 1 addition & 0 deletions hapi/src/gql/eden-transaction.gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const get = async (where, getMany = false) => {
txid
type
updated_at
digest
}
}
`
Expand Down
3 changes: 1 addition & 2 deletions hapi/src/services/dfuse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ const runUpdaters = async actions => {

await updater.apply({
transaction_id: id,
json: matchingAction.json,
timestamp,
ation: matchingAction.name,
election: edenElectionId,
action: matchingAction,
updater
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ module.exports = {
type: 'edenexplorer:categorize',
apply: async action => {
try {
const { new_memo, tx_id, account } = action.json
const { new_memo, tx_id, account, digest = undefined } = action.json
const [, memo] = new_memo?.split(':') || ''

if (!memo) return

const { category, description } = updaterUtil.memoSplit(memo)
const transactionToEditQuery = {
txid: { _eq: tx_id },
type: { _eq: 'expense' },
eden_election: { eden_delegate: { account: { _eq: account } } }
...(digest && { digest: { _eq: digest } })
}

const transactionToEdit = await edenTransactionGql.get(
Expand All @@ -34,7 +33,7 @@ module.exports = {
const updateQuery = {
where: {
id: { _eq: transactionToEdit.id },
type: { _eq: 'expense' }
...(digest && { digest: { _eq: digest } })
},
_set: { category, description, id_election }
}
Expand Down
28 changes: 21 additions & 7 deletions hapi/src/services/dfuse/updaters/eosiotoken-transfer.updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,31 @@ let LASTEST_RATE_DATA_CONSULTED = null
module.exports = {
type: `eosio.token:transfer`,
apply: async action => {
const { quantity, memo, to, from } = action.json
const { quantity, memo, to, from } = action.action.json
const amount = Number(quantity.split(' ')[0] || 0)

const registeredTransaction = await edenTransactionGql.get({
txid: { _eq: action.transaction_id },
amount: { _eq: amount },
memo: { _eq: memo },
recipient: { _eq: to },
type: { _eq: 'expense' }
digest: { _eq: action.action.receipt.digest }
})

if (registeredTransaction) return

const registeredTxWithoutDigest = await edenTransactionGql.get({
txid: { _eq: action.transaction_id },
digest: { _eq: action.transaction_id }
})

if (registeredTxWithoutDigest) {
await edenTransactionGql.update({
where: {
id: { _eq: existTx.id }
},
_set: { digest: action.action.receipt.digest }
})
return
}

let { category, description } = updaterUtil.memoSplit(
memo.split(':')[1] || ''
)
Expand Down Expand Up @@ -72,12 +84,14 @@ module.exports = {
type: 'expense',
eos_exchange: LASTEST_RATE_DATA_CONSULTED,
usd_total: amount * LASTEST_RATE_DATA_CONSULTED,
memo: memo
digest: action.action.receipt.digest
}

await edenTransactionGql.save(transactionData)
} catch (error) {
console.error(`transfer sync error ${action.action}: ${error.message}`)
console.error(
`transfer sync error ${action.action.name}: ${error.message}`
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ module.exports = {
type: `${edenConfig.edenContract}:fundtransfer`,
apply: async action => {
try {
const { amount: quantity, from, distribution_time, rank } = action.json
const {
amount: quantity,
from,
distribution_time,
rank
} = action.action.json
const amount = Number(quantity.split(' ')[0])

const existTx = await edenTransactionGql.get({
Expand Down Expand Up @@ -72,13 +77,13 @@ module.exports = {
const newAmount = existUnclaimedTx.amount - amount

if (newAmount <= 0) {
await deleteTx({
await edenTransactionGql.deleteTx({
where: {
id: { _eq: existUnclaimedTx.id }
}
})
} else {
await update({
await edenTransactionGql.update({
where: {
id: { _eq: existUnclaimedTx.id }
},
Expand All @@ -95,7 +100,7 @@ module.exports = {
}
} catch (error) {
console.error(
`fundtransfer sync error ${action.action}: ${error.message}`
`fundtransfer sync error ${action.action.action.name}: ${error.message}`
)
}
}
Expand Down
3 changes: 3 additions & 0 deletions hapi/src/utils/dfuse.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const getfundTransferQuery = ({ query, lowBlockNum }) => {
}
id
matchingActions {
receipt {
digest
}
account
name
json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ insert_permissions:
permission:
check: {}
columns:
- amount
- category
- created_at
- date
- description
- memo
- digest
- eos_exchange
- id
- id_election
- recipient
- txid
- type
- amount
- eos_exchange
- usd_total
- created_at
- date
- updated_at
- id
- id_election
- usd_total
select_permissions:
- role: guest
permission:
Expand All @@ -33,10 +33,10 @@ select_permissions:
- created_at
- date
- description
- digest
- eos_exchange
- id
- id_election
- memo
- recipient
- txid
- type
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."eden_transaction" add column "digest" varchar
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."eden_transaction" add column "digest" varchar
null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
comment on column "public"."eden_transaction"."memo" is E'Eden Transaction Accounting Standard';
alter table "public"."eden_transaction" alter column "memo" drop not null;
alter table "public"."eden_transaction" add column "memo" varchar;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."eden_transaction" drop column "memo" cascade;
2 changes: 1 addition & 1 deletion webapp/src/gql/eden-expense.gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ export const GET_EXPENSES_BY_ACCOUNT = gql`
recipient
txid
category
memo
eden_election {
election
}
digest
}
}
`
Expand Down
13 changes: 5 additions & 8 deletions webapp/src/hooks/customHooks/useSpendToolsState.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ const useSpendTools = () => {
variables: {
where: {
txid: { _eq: modalData?.txid },
amount: { _eq: modalData?.amount },
recipient: { _eq: modalData?.recipient },
memo: { _eq: modalData?.memo },
type: { _eq: 'expense' }
digest: { _eq: modalData?.digest }
},
_set: {
category: formValuesModal.newCategory,
Expand Down Expand Up @@ -168,11 +165,11 @@ const useSpendTools = () => {
description: formValues.description,
eos_exchange: eosRate,
id_election: idElection,
memo: `eden_expense:${formValues.category}/${formValues.description}`,
recipient: formValues.to,
txid: transactionResult?.transactionId,
type: 'expense',
usd_total: amount * eosRate
usd_total: amount * eosRate,
digest: transactionResult?.transactionId
}

await saveTransaction({
Expand Down Expand Up @@ -214,10 +211,10 @@ const useSpendTools = () => {
}

useEffect(async () => {
setAuthenticatedUser('xavieredenia')
setAuthenticatedUser(state.user?.accountName)

const { data: transactions } = await getTransactions({
account: 'xavieredenia'
account: state.user?.accountName
})

setTransactionsList(transactions?.eden_transaction || [])
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"headerTable3": "AMOUNT",
"headerTable4": "SENT TO",
"headerTable5": "MEMO",
"headerTable6": "CATEGORIZED",
"headerTable6": "CATEGORY",
"headerTable7": "APPEND",
"modalTitle": "Append Memo",
"modalAbout": "Here you can add or change the category and description of previous transactions. First, select the reason for your expense in the selection, then enter your description or reason.",
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/language/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"headerTable3": "MONTO",
"headerTable4": "ENVIADO A",
"headerTable5": "MEMO",
"headerTable6": "CATEGORIZADO",
"headerTable6": "CATEGORIA",
"headerTable7": "CATEGORIZAR",
"modalTitle": "Adjuntar Memo",
"modalAbout": "Aquí puede agregar o cambiar la categoría y descripción de transacciones anteriores. Primero, seleccione el motivo de su gasto en la selección, luego ingrese su descripción o motivo.",
Expand Down
Loading

0 comments on commit 3c32038

Please sign in to comment.