Skip to content

Commit

Permalink
Add Ledger v0.1.0 web support
Browse files Browse the repository at this point in the history
* TRC20 Transfers
* Exchanges Contracts
* Tokens Names
* SR Proposals

Requires tronscan/tronscan-node-client#16
  • Loading branch information
fbsobreira committed Feb 12, 2019
1 parent 8287a0d commit a0ae3f4
Show file tree
Hide file tree
Showing 8 changed files with 2,762 additions and 54 deletions.
49 changes: 25 additions & 24 deletions src/components/account/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,20 +878,21 @@ export default class Account extends Component {
createTxnPair = async (firstTokenId, secondTokenId, firstTokenBalance, secondTokenBalance) => {
let res;
let {account, currentWallet} = this.props;
if (this.state.isTronLink === 1) {
let tronWeb;
if (this.props.walletType.type === "ACCOUNT_LEDGER") {
tronWeb = this.props.tronWeb();
} else if (this.props.walletType.type === "ACCOUNT_TRONLINK") {
tronWeb = account.tronWeb;
}
if (this.props.walletType.type === "ACCOUNT_LEDGER") {
const tronWeb = this.props.tronWeb();
const unSignTransaction = await tronWeb.transactionBuilder.createTRXExchange(firstTokenId, firstTokenBalance, secondTokenBalance, currentWallet.address).catch(e => false);
const {result} = await transactionResultManager(unSignTransaction, tronWeb);
res = result;
}else if (this.props.walletType.type === "ACCOUNT_TRONLINK") {
const tronWeb = account.tronWeb;
const unSignTransaction = await tronWeb.transactionBuilder.createTRXExchange(firstTokenId, firstTokenBalance, secondTokenBalance, tronWeb.defaultAddress.hex).catch(e => false);
const {result} = await transactionResultManager(unSignTransaction, tronWeb);
res = result;
} else {
}else {
const {success} = await Client.createExchange(currentWallet.address, firstTokenId, secondTokenId, firstTokenBalance, secondTokenBalance)(account.key);
res = success;
}

if (res) {
this.setState({
temporaryName: name,
Expand All @@ -917,15 +918,15 @@ export default class Account extends Component {
injectExchange = async (exchangeId, tokenId, quant) => {
let res;
let {account, currentWallet} = this.props;
if (this.state.isTronLink === 1) {
let tronWeb;
if (this.props.walletType.type === "ACCOUNT_LEDGER") {
tronWeb = this.props.tronWeb();
} else if (this.props.walletType.type === "ACCOUNT_TRONLINK") {
tronWeb = account.tronWeb;
}
if (this.props.walletType.type === "ACCOUNT_LEDGER") {
const tronWeb = this.props.tronWeb();
const unSignTransaction = await tronWeb.transactionBuilder.injectExchangeTokens(exchangeId, tokenId, quant, currentWallet.address).catch(e => false);
const {result} = await transactionResultManager(unSignTransaction, tronWeb);
res = result;
}else if (this.props.walletType.type === "ACCOUNT_TRONLINK") {
const tronWeb = account.tronWeb;
const unSignTransaction = await tronWeb.transactionBuilder.injectExchangeTokens(exchangeId, tokenId, quant, tronWeb.defaultAddress.hex).catch(e => false);
const {result} = await transactionResultManager(unSignTransaction, tronWeb);
const {result} = await transactionResultManager(unSignTransaction, tronWeb);
res = result;
} else {
const {success} = await Client.injectExchange(currentWallet.address, exchangeId, tokenId, quant)(account.key);
Expand Down Expand Up @@ -956,15 +957,15 @@ export default class Account extends Component {
withdrawExchange = async (exchangeId, tokenId, quant) => {
let res;
let {account, currentWallet} = this.props;
if (this.state.isTronLink === 1) {
let tronWeb;
if (this.props.walletType.type === "ACCOUNT_LEDGER") {
tronWeb = this.props.tronWeb();
} else if (this.props.walletType.type === "ACCOUNT_TRONLINK") {
tronWeb = account.tronWeb;
}
if (this.props.walletType.type === "ACCOUNT_LEDGER") {
const tronWeb = this.props.tronWeb();
const unSignTransaction = await tronWeb.transactionBuilder.withdrawExchangeTokens(exchangeId, tokenId, quant, currentWallet.address).catch(e => false);
const {result} = await transactionResultManager(unSignTransaction, tronWeb);
res = result;
}else if (this.props.walletType.type === "ACCOUNT_TRONLINK") {
const tronWeb = account.tronWeb;
const unSignTransaction = await tronWeb.transactionBuilder.withdrawExchangeTokens(exchangeId, tokenId, quant, tronWeb.defaultAddress.hex).catch(e => false);
const {result} = await transactionResultManager(unSignTransaction, tronWeb)
const {result} = await transactionResultManager(unSignTransaction, tronWeb);
res = result;
} else {
const {success} = await Client.withdrawExchange(currentWallet.address, exchangeId, tokenId, quant)(account.key);
Expand Down
2 changes: 1 addition & 1 deletion src/components/tokens/TokenCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class TokenCreate extends Component {
description: this.state.description,
url: this.state.url,
totalSupply: this.state.totalSupply * Math.pow(10, Number(this.state.precision)),
tokenRatio: this.state.numberOfCoins,
tokenRatio: this.state.numberOfCoins * Math.pow(10, Number(this.state.precision)),
trxRatio: this.state.numberOfTron * ONE_TRX,
saleStart: Date.parse(this.state.startTime),
saleEnd: Date.parse(this.state.endTime),
Expand Down
5 changes: 2 additions & 3 deletions src/hw/ledger/LedgerBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ export default class LedgerBridge {
const transport = await Transport.create();
try {
const trx = new AppTrx(transport);
let response = await trx.signTransaction(
let response = await trx.signTransactionWithTokenName(
this.path,
transaction.hex,
false, //transaction.sha256,
transaction.contractType);
transaction.info);
resolve(response);
} catch(e) {
reject(e);
Expand Down
Loading

0 comments on commit a0ae3f4

Please sign in to comment.