Skip to content

Commit

Permalink
Merge pull request #412 from edenia/dev
Browse files Browse the repository at this point in the history
Production Release
  • Loading branch information
xavier506 authored Jan 17, 2023
2 parents 6e1efdf + 35b1d28 commit 2bb80e8
Show file tree
Hide file tree
Showing 39 changed files with 545 additions and 189 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push-dev-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
IMAGE_NAME_HAPI: eden-spending-hapi-dev
IMAGE_NAME_HASURA: eden-spending-hasura-dev
IMAGE_NAME_WALLET: eden-spending-wallet-dev
# Postgres-0
# Postgres
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push-prod-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
HAPI_DFUSE_API_KEY: ${{secrets.HAPI_DFUSE_API_KEY}}
HAPI_DFUSE_API: eos.dfuse.eosnation.io
HAPI_DFUSE_FIRST_BLOCK: 209174091
HAPI_DFUSE_FIRST_TREASURY_BLOCK: 183728436
HAPI_DFUSE_FIRST_TREASURY_BLOCK: 205528491
# hasura
HASURA_GRAPHQL_ENABLE_CONSOLE: true
HASURA_GRAPHQL_DATABASE_URL: ${{ secrets.HASURA_GRAPHQL_DATABASE_URL }}
Expand Down
5 changes: 3 additions & 2 deletions contract/edenexplorer/include/edenexplorer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace eden {

void categorize( eosio::name account,
std::string &new_memo,
std::string &tx_id );
std::string &tx_id,
std::string &digest );

bool parse_memo( std::string &memo );

Expand All @@ -35,6 +36,6 @@ namespace eden {

EOSIO_ACTIONS( edenexplorer_contract,
"edenexplorer"_n,
action( categorize, account, new_memo, tx_id ) )
action( categorize, account, new_memo, tx_id, digest ) )

} // namespace eden
4 changes: 3 additions & 1 deletion contract/edenexplorer/src/edenexplorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace eden {

void edenexplorer_contract::categorize( eosio::name account,
std::string &new_memo,
std::string &tx_id ) {
std::string &tx_id,
std::string &digest ) {
require_auth( account );

eosio::action{ { get_self(), "active"_n },
Expand All @@ -20,6 +21,7 @@ namespace eden {
"Incorrect format or category, use: 'eden_expense: "
"<category>/<description>'" );
eosio::check( tx_id.length() == 64, "Incorrect length transaction id" );
eosio::check( digest.length() == 64, "Incorrect length digest id" );
}

bool edenexplorer_contract::exist_category( std::string &category_name ) {
Expand Down
19 changes: 18 additions & 1 deletion contract/edenexplorer/tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ TEST_CASE( "Require to be an eden member" ) {
tester t;

expect( t.edenexplorer.trace< eden::actions::categorize >( "alice"_n,
"testing",
"testing",
"testing" ),
"missing authority of alice" );
Expand All @@ -16,6 +17,7 @@ TEST_CASE( "Requiere the right memo format" ) {
tester t;

expect( t.edenexplorer.trace< eden::actions::categorize >( "edenexplorer"_n,
"testing",
"testing",
"testing" ),
"assertion failure with message: Incorrect format or category, use: "
Expand All @@ -28,6 +30,7 @@ TEST_CASE( "Requiere a right category" ) {
expect( t.edenexplorer.trace< eden::actions::categorize >(
"edenexplorer"_n,
"eden_expense: testing/expense for pay EOSIO developers",
"testing",
"testing" ),
"assertion failure with message: Incorrect format or category, use: "
"'eden_expense: <category>/<description>'" );
Expand All @@ -39,15 +42,29 @@ TEST_CASE( "Requiere the right length for tx_id" ) {
expect( t.bob.trace< eden::actions::categorize >(
"bob"_n,
"eden_expense: development/expense for pay EOSIO developers",
"testing",
"testing" ),
"assertion failure with message: Incorrect length transaction id" );
}

TEST_CASE( "Requiere the right length for digest" ) {
tester t;

expect(
t.bob.trace< eden::actions::categorize >(
"bob"_n,
"eden_expense: development/expense for pay EOSIO developers",
"96dda25da00b945e5b696a8a4b01453c97973c78dc766a885b73e28bd42f6cc5",
"testing" ),
"assertion failure with message: Incorrect length digest id" );
}

TEST_CASE( "Succes action" ) {
tester t;

expect( t.bob.trace< eden::actions::categorize >(
"bob"_n,
"eden_expense: infrastructure/expense for pay EOSIO developers",
"96dda25da00b945e5b696a8a4b01453c97973c78dc766a885b73e28bd42f6cc5" ) );
"96dda25da00b945e5b696a8a4b01453c97973c78dc766a885b73e28bd42f6cc5",
"f3f57eaf6efe030d6af4c77818daec081e505fde4c2b15cfdad950f636400b8b" ) );
}
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: registeredTxWithoutDigest.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;
18 changes: 9 additions & 9 deletions webapp/src/components/BarChartReport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const BarChartReport = ({
const { t } = useTranslation()
const [selectedUSD, setSelected] = useState(false)
const [coinType, setCoinType] = useState('EOS')
const width = window.innerWidth

const handleChange = event => {
setSelected(event.target.checked)
Expand Down Expand Up @@ -166,12 +167,7 @@ const BarChartReport = ({
</div>
</div>
<div className={classes.chartContainer}>
<ResponsiveContainer
minWidth={600}
width="100%"
height={300}
marginTop="16px"
>
<ResponsiveContainer width="100%" height={300} marginTop="16px">
<ComposedChart height={300} data={data} ref={barRef}>
<CartesianGrid stroke="#f0f0f0" />
<XAxis
Expand All @@ -197,7 +193,7 @@ const BarChartReport = ({
)}
<Bar
dataKey={`${coinType}_UN${category.toLocaleUpperCase()}`}
barSize={35}
barSize={width > 600 ? 35 : 15}
fill="#f4d35e"
>
{data.map(({ election }) => (
Expand All @@ -206,14 +202,18 @@ const BarChartReport = ({
</Bar>
<Bar
dataKey={`${coinType}_${category.toLocaleUpperCase()}`}
barSize={35}
barSize={width > 600 ? 35 : 15}
fill="#ee964b"
>
{data.map(({ election }) => (
<Cell key={`cell-${election}`} />
))}
</Bar>
<Bar dataKey={`${coinType}_TOTAL`} barSize={35} fill="#19647e">
<Bar
dataKey={`${coinType}_TOTAL`}
barSize={width > 600 ? 35 : 15}
fill="#19647e"
>
{data.map(({ election }) => (
<Cell key={`cell-${election}`} />
))}
Expand Down
10 changes: 8 additions & 2 deletions webapp/src/components/BarChartReport/styles.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
export default theme => ({
root: {
margin: theme.spacing(6, 6, 6, 6)
margin: theme.spacing(6, 6, 6, 6),
[theme.breakpoints.down('sm')]: {
margin: theme.spacing(6, 1, 6, 1)
}
},
chartContainer: {
whiteSpace: 'nowrap',
overflowY: 'hidden'
overflowY: 'hidden',
[theme.breakpoints.down('sm')]: {
overflowX: 'hidden'
}
},
title: {
'& span': {
Expand Down
Loading

0 comments on commit 2bb80e8

Please sign in to comment.