Skip to content

Commit

Permalink
fix: [ADN-228] Fix approval injection popup for ledger account (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Jun 2, 2023
1 parent 10ab247 commit a0b9b06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
18 changes: 12 additions & 6 deletions packages/adena-extension/src/pages/wallet/approve-sign/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import DefaultFavicon from './../../../assets/favicon-default.svg';
import styled from 'styled-components';
import Text from '@components/text';
Expand Down Expand Up @@ -100,27 +100,33 @@ export const ApproveSign = () => {
return false;
};

const createLedgerTransaction = useCallback(async () => {
const createLedgerTransaction = async () => {
if (!currentAccount || !gnoClient || !document) {
return false;
}
if (!isLedgerAccount(currentAccount)) {
return false;
}

await transactionService.createSignature(currentAccount, document).then(async (signature) => {
const result = await transactionService.createSignatureWithLedger(currentAccount, document).then(async (signature) => {
chrome.runtime.sendMessage(
InjectionMessageInstance.success('SIGN_AMINO', { document, signature }, requestData?.key),
);
return true;
}).catch((error: Error) => {
if (error.message === 'Transaction signing request was rejected by the user') {
cancelEvent();
chrome.runtime.sendMessage(
InjectionMessageInstance.failure('SIGN_FAILED', requestData?.data, requestData?.key),
);
return true;
}
if (error.message.includes('Ledger')) {
return false;
}
return false;
});
return false;
}, [currentAccount, gnoClient, document]);
return result;
};

const signTransaction = async () => {
if (transactionData && gnoClient && currentAccount) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from 'react';
import React, { useEffect, useState } from 'react';
import DefaultFavicon from './../../../assets/favicon-default.svg';
import styled from 'styled-components';
import Text from '@components/text';
Expand All @@ -14,9 +14,7 @@ import Button from '@components/buttons/button';
import IconArraowDown from '@assets/arrowS-down-gray.svg';
import IconArraowUp from '@assets/arrowS-up-gray.svg';
import { useAdenaContext } from '@hooks/use-context';
import { LedgerConnector } from 'adena-module';
import { isLedgerAccount } from 'adena-module';
import { StdSignDoc } from 'adena-module/src';
import { LedgerConnector, isLedgerAccount, StdSignDoc } from 'adena-module';

function mappedTransactionData(document: StdSignDoc) {
return {
Expand Down Expand Up @@ -102,34 +100,37 @@ export const ApproveTransactionMain = () => {
return false;
};

const createLedgerTransaction = useCallback(async () => {
const createLedgerTransaction = async () => {
if (!currentAccount || !gnoClient || !document) {
return false;
}
if (!isLedgerAccount(currentAccount)) {
return false;
}

await transactionService.createSignature(currentAccount, document).then(async (signature) => {
const result = await transactionService.createSignatureWithLedger(currentAccount, document).then(async (signature) => {
const transaction = await transactionService.createTransaction(document, signature);
const result = await transactionService.sendTransaction(gnoClient, transaction);
if (result.height && result.height !== '0') {
chrome.runtime.sendMessage(
InjectionMessageInstance.success('TRANSACTION_SENT', result, requestData?.key),
);
return true;
}
chrome.runtime.sendMessage(
InjectionMessageInstance.failure('TRANSACTION_FAILED', result, requestData?.key),
);
return true;
}).catch((error: Error) => {
if (error.message.includes('Ledger')) {
return false;
}
if (error.message === 'Transaction signing request was rejected by the user') {
cancelEvent();
}
return false;
});
return false;
}, [currentAccount, gnoClient, document]);
return result;
};

const sendTransaction = async () => {
if (document && gnoClient && currentAccount) {
Expand Down

0 comments on commit a0b9b06

Please sign in to comment.