Skip to content

Commit

Permalink
Changed it to only update MWC/GRIN address after successfully receivi…
Browse files Browse the repository at this point in the history
…ng or sending a transaction
  • Loading branch information
NicolasFlamel1 committed Oct 27, 2022
1 parent 1125a57 commit 7a9fff2
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 247 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import type { Observable } from "rxjs";
import type { AccountRaw, Address } from "@ledgerhq/types-live";
import type { AccountRaw } from "@ledgerhq/types-live";
import type { TransactionRaw } from "@ledgerhq/live-common/generated/types"
import { withDevice } from "@ledgerhq/live-common/hw/deviceAccess";
import prepareTransaction from "@ledgerhq/live-common/families/mimblewimble_coin/prepareTransaction";
Expand All @@ -23,10 +23,7 @@ const cmd = ({
id: string,
offset: string,
proof: string | undefined,
encryptedSecretNonce: string,
address: Address,
identifier: string,
freshAddress: Address,
encryptedSecretNonce: string
}> => withDevice(deviceId)(transport => from(prepareTransaction(account, transport, transaction)));

export default cmd;
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ import ModalBody from "~/renderer/components/Modal/ModalBody";
import QRCode from "~/renderer/components/QRCode";
import styled from "styled-components";
import Button from "~/renderer/components/Button";
import { validateTransactionResponse, addSentTransactionToAccount, identifierFromString, addPreparedTransactionToAccount, addUnbroadcastTransactionToAccount } from "@ledgerhq/live-common/families/mimblewimble_coin/react";
import { validateTransactionResponse, addSentTransactionToAccount } from "@ledgerhq/live-common/families/mimblewimble_coin/react";
import BigNumber from "bignumber.js";
import { deserializeError } from "@ledgerhq/errors";
import { MimbleWimbleCoinSerializedError } from "@ledgerhq/live-common/families/mimblewimble_coin/errors";

const connectAppExec = command("connectApp");

Expand Down Expand Up @@ -111,9 +109,6 @@ class StepConnectDevice extends PureComponent<Props, State> {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined
}));
}
Expand All @@ -130,8 +125,7 @@ class StepConnectDevice extends PureComponent<Props, State> {
onTransactionError,
transitionTo,
closeModal,
onChangeTransaction,
updateAccountWithUpdater
onChangeTransaction
} = this.props;
const {
currentDevice
Expand All @@ -151,20 +145,14 @@ class StepConnectDevice extends PureComponent<Props, State> {
id,
offset,
proof,
encryptedSecretNonce,
address,
identifier,
freshAddress
encryptedSecretNonce
}: {
transactionData: string;
height: string;
id: string;
offset: string;
proof: string | undefined;
encryptedSecretNonce: string;
address: Address;
identifier: string;
freshAddress: Address;
}
) => {
qrcode.toString(transactionData, {
Expand All @@ -184,16 +172,8 @@ class StepConnectDevice extends PureComponent<Props, State> {
id,
offset: Buffer.from(offset, "hex"),
proof: (proof !== undefined) ? Buffer.from(proof, "hex") : undefined,
encryptedSecretNonce: Buffer.from(encryptedSecretNonce, "hex"),
address,
identifier: identifierFromString(identifier),
freshAddress
encryptedSecretNonce: Buffer.from(encryptedSecretNonce, "hex")
}));
updateAccountWithUpdater(mainAccount.id, (
account: Account
) => {
return addPreparedTransactionToAccount(account, freshAddress, identifier);
});
}
});
},
Expand Down Expand Up @@ -353,10 +333,8 @@ class StepConnectDevice extends PureComponent<Props, State> {
closeModal,
onFailHandler,
onTransactionError,
updateAccountWithUpdater,
transaction
updateAccountWithUpdater
} = this.props;
const mainAccount = getMainAccount(account, parentAccount);
if(signedOperation) {
setSigned(true);
this.broadcast(signedOperation).then((
Expand All @@ -370,6 +348,7 @@ class StepConnectDevice extends PureComponent<Props, State> {
closeModal();
onConfirmationHandler(operation);
}
const mainAccount = getMainAccount(account, parentAccount);
updateAccountWithUpdater(mainAccount.id, (
account: Account
) => {
Expand All @@ -387,45 +366,16 @@ class StepConnectDevice extends PureComponent<Props, State> {
closeModal();
onFailHandler(error);
}
updateAccountWithUpdater(mainAccount.id, (
account: Account
) => {
return addUnbroadcastTransactionToAccount(account, signedOperation);
});
});
}
else if(transactionSignError) {
if(transactionSignError instanceof MimbleWimbleCoinSerializedError) {
const {
error,
freshAddress,
identifier
} = JSON.parse(transactionSignError.message);
if(!onFailHandler) {
onTransactionError(deserializeError(error));
transitionTo("confirmation");
}
else {
closeModal();
onFailHandler(deserializeError(error));
}
if(transaction.transactionResponse === undefined && freshAddress) {
updateAccountWithUpdater(mainAccount.id, (
account: Account
) => {
return addPreparedTransactionToAccount(account, freshAddress, identifier);
});
}
if(!onFailHandler) {
onTransactionError(transactionSignError);
transitionTo("confirmation");
}
else {
if(!onFailHandler) {
onTransactionError(transactionSignError);
transitionTo("confirmation");
}
else {
closeModal();
onFailHandler(transactionSignError);
}
closeModal();
onFailHandler(transactionSignError);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ const inferTransactions = (
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: Consensus.getDefaultBaseFee(mainAccount.currency),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "500000",
Expand All @@ -77,9 +74,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "500000",
Expand All @@ -105,9 +99,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "500000",
Expand All @@ -133,9 +124,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "500000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "500000",
Expand All @@ -77,9 +74,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "500000",
Expand All @@ -105,9 +99,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "500000",
Expand All @@ -133,9 +124,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "500000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "1000000",
Expand All @@ -77,9 +74,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "1000000",
Expand All @@ -105,9 +99,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "1000000",
Expand All @@ -133,9 +124,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "1000000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "1000000",
Expand All @@ -77,9 +74,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "1000000",
Expand All @@ -105,9 +99,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "1000000",
Expand All @@ -133,9 +124,6 @@ export default {
offset: undefined,
proof: undefined,
encryptedSecretNonce: undefined,
address: undefined,
identifier: undefined,
freshAddress: undefined,
transactionResponse: undefined,
useDefaultBaseFee: true,
baseFee: "1000000",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,3 @@ export const MimbleWimbleCoinMaxFeeExceeded = createCustomErrorClass(
export const MimbleWimbleCoinInvalidBaseFee = createCustomErrorClass(
"MimbleWimbleCoinInvalidBaseFee"
);

export const MimbleWimbleCoinSerializedError = createCustomErrorClass(
"MimbleWimbleCoinSerializedError"
);
Loading

0 comments on commit 7a9fff2

Please sign in to comment.