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

One integration #170

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

One integration #170

wants to merge 11 commits into from

Conversation

potvik
Copy link

@potvik potvik commented Jun 24, 2020

No description provided.

async importPrivateKey(privateKey: string): { oneKey: string } | void {
this.connectApi()

const account = await this.harmonyApi.wallet.addByPrivateKey(privateKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to check for mnemonic and check for validity.

Copy link
Author

Choose a reason for hiding this comment

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

Done

}
}

async createPrivateKey(walletType: string): Promise<Object> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Create and save mnemonic.

Copy link
Author

Choose a reason for hiding this comment

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

Done


async connectApi(walletId?: string): Promise<void> {
if (!this.harmonyApi.blockchain) {
this.harmonyApi = new Harmony(URL_MAINNET, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Need ability to connect to multiple different urls.

Copy link
Author

Choose a reason for hiding this comment

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

Done - added multiple servers support

throw new Error('InvalidPublicAddressError')
}

edgeParsedUri.uniqueIdentifier = parsedUri.query.dt || undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

Confirming you are also using dt as a unique identifier and not just copied.

Copy link
Author

Choose a reason for hiding this comment

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

Removed this line


async encodeUri(obj: EdgeEncodeUri): Promise<string> {
try {
this.harmonyApi.crypto.getAddress(obj.publicAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

Connect to api to ensure it exists.

Copy link
Author

Choose a reason for hiding this comment

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

connectApi removed. this.harmonyApi initiated in constructor

if (this.walletLocalData.publicKey === tx.to) {
name = tx.from
} else {
name = tx.to
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't assign name. It is meant for human readable text not addresses.

Copy link
Author

Choose a reason for hiding this comment

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

Removed

name = tx.to
}

let nativeAmount = String(Number(tx.value))
Copy link
Contributor

Choose a reason for hiding this comment

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

What is tx.value? If its a hex then you can just plug it into bns. Converting to a Number first will cause it to lose precision.

i.e.

let nativeAmount = bns.add('0', tx.value)

Copy link
Author

Choose a reason for hiding this comment

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

Done

currencyCode,
blockHeight: Number(tx.blockNumber),
nativeAmount,
networkFee: String(networkFee),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should already be a string.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

throw new Error('Error: no amount specified')
}

if (!nativeAmount || nativeAmount === '0') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't send 0 amounts? Ethereum can

Copy link
Author

Choose a reason for hiding this comment

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

We can send 0 amounts. Removed this validation

const GAS_PRICE = new Unit('1').asGwei().toHex()
const GAS_LIMIT_BASE = new Unit('21000').asWei().toHex()

const nativeNetworkFee = String(GAS_PRICE * GAS_LIMIT_BASE)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same code is being executed over and over. Should be pulled out and be a constant value unless you plan on making this dynamic values.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed (moved to otherData)

@peachbits
Copy link
Contributor

@potvik Please run yarn precommit and resolve the remaining flow errors. Once ready we can get this to QA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants