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

add xchain-haven #588

Closed
wants to merge 304 commits into from
Closed

Conversation

MartyHav
Copy link

@MartyHav MartyHav commented May 24, 2022

This PR adds xchain-haven package.

a few marks:

Besides of these points, this PR is ready to be reviewed.

@MartyHav MartyHav marked this pull request as ready for review May 24, 2022 11:18
@veado
Copy link
Collaborator

veado commented May 26, 2022

Thx for your PR!

* xchain-util is included as a local package as the npm version, doesn't include enum Chain.Haven yet
  https://github.com/haven-protocol-org/xchainjs-lib/blob/261e0371771a0331fd1489d62f872b0d0f90e90a/packages/xchain-haven/package.json#L37

Pls add Chain.Haven to xchain-util (ah, you already have done it), bump xchain-util to a next patch version + add its new version to xchain-haven. To test it locally in your xchain-haven, just run yarn build in xchain-util once.

* mnemonicConverter is included as a GitHub package and set to latest commit. It exposes two functions, where you can either convert a bip39 phrase into a haven or monero mnemonic. It was planed to move this package/functionality to xchain-crypto package and I would like to leave this to xchainjs maintainers.
  https://github.com/haven-protocol-org/xchainjs-lib/blob/261e0371771a0331fd1489d62f872b0d0f90e90a/packages/xchain-haven/package.json#L40

Pls add it to xchain-util as well (another PR is recommend, this PR ^ has already ~5k LOC).

* haven-core-js the underlying wallet library/sdk is included as a GitHub package as well for now. I'll create a npm package of it shortly.

Yes, pls add a npm package.

Thanks again!

packages/xchain-haven/README.md Outdated Show resolved Hide resolved
packages/xchain-haven/README.md Outdated Show resolved Hide resolved
packages/xchain-haven/__tests__/haven-core.test.ts Outdated Show resolved Hide resolved
packages/xchain-haven/__tests__/openhaven-api.test.ts Outdated Show resolved Hide resolved
packages/xchain-haven/package.json Outdated Show resolved Hide resolved
packages/xchain-haven/package.json Outdated Show resolved Hide resolved
packages/xchain-haven/src/client.ts Outdated Show resolved Hide resolved
@mikewyszinski
Copy link
Collaborator

also can you merge the latest from master and add a changelog?

@MartyHav
Copy link
Author

@veado Implemented all your remarks and added a new PR: #593 for bip 39 phrase converter. Just saw you wanted to have it in xchain-util and not in xchain-crypto, would be a quick change, we can sort it out there.

@MartyHav
Copy link
Author

also can you merge the latest from master and add a changelog?

yes merged and added changelog. Should changelog be maintained while PR is ongoing?

Copy link
Collaborator

@veado veado left a comment

Choose a reason for hiding this comment

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

Nice PR! Some comments have been added...

yarn lint
...
✖ 29 problems (1 error, 28 warnings)

Pls don't forget to run yarn lint

})

it('should not throw an error for setting a good phrase', () => {
expect(havenClient.setPhrase(bip39Mnemonic)).toBeUndefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo .toBeUndefined() (note missing ()) or better .not.toThrow()

it('should send funds', async () => {
havenClient.setNetwork(Network.Testnet)
havenClient.setPhrase(bip39Mnemonic)
const amount = baseAmount(2223, 12)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems 12 is default decimal. Pls add const XHV_DECIMAL = 12 into utils.ts

}

async getTransactions(params?: TxHistoryParams): Promise<TxsPage> {
const asset: Asset | undefined = params?.asset ? assetFromString(params.asset)! : undefined
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoid !, lint will tell you Forbidden non-null assertion.

const asset: Asset | null = params?.asset ? assetFromString(params.asset) : null

Or even better: TxHistoryParams in xchain-client needs to be updated to include asset?: Asset (not asset: string). Can be done by another PR.

Copy link
Author

Choose a reason for hiding this comment

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

But this PR would be a breaking change, right?

// Limit should work
const xhvAsset = AssetXHV
const txPages = await havenClient.getTransactions({ address: 'ignored', asset: assetToString(xhvAsset) })
return expect(txPages.txs[0].asset).toEqual(AssetXHV)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hint: To compare assets, use eqAsset from xchain-util

expect(eqAsset(txPages.txs[0].asset, AssetXHV)).toBeTruthy()

it('should transfer funds', async () => {
client.init(mnenomonic, NetTypes.testnet)
// is equal to 0.1 XHV
const transferAmount = new BigNumber(10).exponentiatedBy(12).dividedBy(100)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are helpers in xchain-utils for doing similar things ^

const transferAmount: BaseAmount = assetToBase(assetAmount(0.1, 12))
  • assetAmount(0.1, 12) => 0.1 XHV
  • assetToBase converts it ^ to smallest unit => 10000000000

this.syncHandler.purge()
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
clearInterval(this.pingServerIntervalID)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to follow eslint, e.g.

this.pingServerIntervalID && clearInterval(this.pingServerIntervalID)


const lockedBalance = balance.subtract(unlockedBalance)

havenBalance[assetType as HavenTicker] = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to avoid assetType as HavenTicker (see previous comments to similar topic)


if (this.base_fee === undefined || this.fork_version === undefined) {
const version = await get_version()
this.fork_version = version.fork_version as number
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to cast the result if get_version will return a proper type (not any). Pls check previous comment to missing API types.

Comment on lines 299 to 301
const updateStatus = (_status: any) => {
//console.log(status)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is updateStatus still needed ^?

if (!(await this.isSyncing())) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
clearInterval(this.updateSyncProgressIntervalID) // eslint-disable-next-line @typescript-eslint/ban-ts-comment
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to ignore/disable eslint: this.updateSyncProgressIntervalID might be undefined, just add a check before (similar you have done in purge)

Copy link
Collaborator

@Thorian1te Thorian1te left a comment

Choose a reason for hiding this comment

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

Looks good to me. 👍

@MartyHav
Copy link
Author

Nice PR! Some comments have been added...

yarn lint
...
✖ 29 problems (1 error, 28 warnings)

Pls don't forget to run yarn lint

Fixed all lint warnings/errors. Also fixed/improved the code parts you addressed in your comments.
Thanks for the review so far!

@MartyHav MartyHav requested a review from veado June 12, 2022 12:56
@MartyHav MartyHav requested a review from Thorian1te June 28, 2022 09:15
@github-actions github-actions bot added the stale label Sep 20, 2023
@github-actions github-actions bot closed this Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants