Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: added a "common" package to share code between packages #151

Merged
merged 30 commits into from
May 30, 2024

Conversation

andreabadesso
Copy link
Collaborator

@andreabadesso andreabadesso commented Apr 1, 2024

Motivation

We should have a common package so that the wallet-service and the daemon can share code between them.

This PR does not attempt to refactor both projects, but only to create the common project and include the bare minimum changes to enable code sharing of the nft util

Acceptance Criteria

  • We should migrate the addAlert from the daemon's package to the common package and use it on both the wallet-service and the daemon
  • We should migrate types related to transactions and use them in the daemon

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged
  • Make sure either the unit tests and/or the QA tests are capable of testing the new features
  • Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.

@andreabadesso andreabadesso self-assigned this Apr 1, 2024
@andreabadesso andreabadesso added the enhancement New feature or request label Apr 1, 2024
package.json Outdated
Comment on lines 32 to 40
"@aws-sdk/client-apigatewaymanagementapi": "3.540.0",
"@aws-sdk/client-lambda": "3.540.0",
"@aws-sdk/client-sqs": "3.540.0",
"@hathor/wallet-lib": "0.39.0",
"bip32": "^4.0.0",
"bitcoinjs-lib": "^6.1.5",
"bitcoinjs-message": "^2.2.0",
"tiny-secp256k1": "^2.2.3",
"winston": "^3.13.0"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added those dependencies here so the projects can use peerDependencies and share the dependency

@andreabadesso andreabadesso force-pushed the refactor/common-project branch from e66536d to 81d2a6d Compare April 1, 2024 18:10
@andreabadesso andreabadesso requested review from tuliomir, r4mmer and pedroferreira1 and removed request for r4mmer April 1, 2024 19:21
@andreabadesso andreabadesso changed the title refactor: common project refactor: added a "common" package to share code between packages Apr 1, 2024
@andreabadesso andreabadesso force-pushed the refactor/common-project branch 5 times, most recently from deb36e6 to 8da7285 Compare April 3, 2024 15:22
@@ -28,9 +28,9 @@ export const addAlert = async (
title: string,
message: string,
severity: Severity,
metadata?: unknown,
metadata: unknown = null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you set this default value? Shouldn't we have the optional parameters in the end of the method?

Copy link
Collaborator Author

@andreabadesso andreabadesso Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment in this line: a410a8c

I'll refactor the logger to be shared between projects, so logger will stop being a parameter there, so this default to null is temporary until then

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand the default null. We use default values for parameters in the end of the list of parameters, which is not the case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the null default in cae81ac

WARNING = 'warning',
INFO = 'info',
}
export { Severity, Transaction, TxInput, TxOutput, DecodedOutput };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to export the imported types?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't, this was done initially because I was only planning to move the types on the next PR

But refactored the code to import from the common project, can you please check again?

@andreabadesso andreabadesso force-pushed the refactor/common-project branch 3 times, most recently from 1d73093 to 49a3744 Compare April 5, 2024 16:13
@@ -4,7 +4,8 @@ import eventTemplate from '@events/eventTemplate.json';
import { loadWallet, loadWalletFailed } from '@src/api/wallet';
import { createWallet, getMinersList } from '@src/db';
import * as txProcessor from '@src/txProcessor';
import { Transaction, WalletStatus, TxInput, Severity } from '@src/types';
import { WalletStatus } from '@src/types';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Lint fix

Suggested change
import { WalletStatus } from '@src/types';
import { WalletStatus } from '@src/types';

Copy link
Collaborator Author

@andreabadesso andreabadesso Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 408d995

@@ -6,7 +6,8 @@ import { sendMulticastMock, messaging, initFirebaseAdminMock } from '@tests/util
import { logger } from '@tests/winston.mock';
import { PushNotificationUtils, PushNotificationError, buildFunctionName, FunctionName } from '@src/utils/pushnotification.utils';
import * as pushnotificationUtils from '@src/utils/pushnotification.utils';
import { SendNotificationToDevice, Severity } from '@src/types';
import { SendNotificationToDevice } from '@src/types';
import { Severity } from '@wallet-service/common/src/types';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Lint fix

Suggested change
import { Severity } from '@wallet-service/common/src/types';
import { Severity } from '@wallet-service/common/src/types';

Copy link
Collaborator Author

@andreabadesso andreabadesso Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 408d995

"peerDependencies": {
"@aws-sdk/client-lambda": "3.540.0",
"@hathor/wallet-lib": "0.39.0",
"winston": "^3.13.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question(non-blocking): Here we have a mix of version definitions. Some are pinned to an exact value and some are with a flexible caret range.

Should we decide for one approach or another? Or can we leave this mixed as it currently is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix all versions in a future PR

package.json Outdated
Comment on lines 5 to 7
"packages/daemon",
"packages/wallet-service"
"packages/wallet-service",
"packages/common"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Order this alphabetically, as it will probably be automatically fixed at some point in the future

    "packages/common",
    "packages/daemon",
    "packages/wallet-service"

Copy link
Collaborator Author

@andreabadesso andreabadesso Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 408d995

@andreabadesso andreabadesso force-pushed the refactor/common-project branch from 6506f1f to 8604db6 Compare April 15, 2024 01:32
@andreabadesso andreabadesso force-pushed the refactor/common-project branch 2 times, most recently from 16ba61f to 9d84734 Compare May 1, 2024 17:57
* feat: added nft utils

* tests: added tests for common utils

* chore: added common module to CI

* refactor: moved used types to common package

* tests: removed nft utils

* tests: fixed nft tests on txProcessor

* tests: mocking network on getconfig

* tests: fixed nft tests on txProcessor

* refactor: passing logger to invoke nft handler

* refactor: no need to ignore ts

* chore: removed jest script, instead using only test

* chore: added hathor header

* refactor: using common utils on txProcessor

* tests: nft utils using old syntax

* tests: skipped txProcessor tests

* tests: fixed txProcessor tests

* refactor: using isAuthority from common utils

* refactor: using isAuthority from common types

* refactor: using assertEnvVariablesExistance from common project

* refactor: getting CREATE_NFT_MAX_RETRIES from env

* docs: updated docstrings on nft utils

* chore: removed events/nftCreationTx.ts

* refactor: invalid import locations

* refactor: remove unused lambdas (#155)

* tests: fixed nft tests on txProcessor

* refactor: removed all methods related to the old wallet-service txProcessor
@andreabadesso andreabadesso force-pushed the refactor/common-project branch from 9d84734 to 25261a1 Compare May 4, 2024 00:53
* refactor: logger is now a required param in addAlert, refactored all methods in wallet-service package

* chore: changed module resolution and several package locks

* chore: added common library to externals whitelist and whitelisted it in tsloader

* chore: wallet-service common package moved from direct path to workspace

* chore: added common as a peer dependency and restored peer dependencies

* chore: removed peer dependencies as they were not working with serverless-monorepo

* chore: added comment on hoisting limits

* chore: added comment explaining externals in webpack
@andreabadesso andreabadesso merged commit 5f83d3e into master May 30, 2024
1 check passed
@andreabadesso andreabadesso deleted the refactor/common-project branch May 30, 2024 00:58
This was referenced Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants