-
Notifications
You must be signed in to change notification settings - Fork 95
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
add xchain-haven #588
Conversation
Thx for your PR!
Pls
Pls add it to
Yes, pls add a npm package. Thanks again! |
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? |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
packages/xchain-haven/src/client.ts
Outdated
} | ||
|
||
async getTransactions(params?: TxHistoryParams): Promise<TxsPage> { | ||
const asset: Asset | undefined = params?.asset ? assetFromString(params.asset)! : undefined |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 XHVassetToBase
converts it ^ to smallest unit =>10000000000
this.syncHandler.purge() | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
//@ts-ignore | ||
clearInterval(this.pingServerIntervalID) |
There was a problem hiding this comment.
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] = { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
const updateStatus = (_status: any) => { | ||
//console.log(status) | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
)
There was a problem hiding this 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. 👍
Fixed all lint warnings/errors. Also fixed/improved the code parts you addressed in your comments. |
This PR adds xchain-haven package.
a few marks:
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
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
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.
Besides of these points, this PR is ready to be reviewed.