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

Use totalCost in place of suggestedFeeMutez #287

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const SubmitApproveOrExecuteForm: React.FC<Props> = ({
<Heading size="sm" color="text.dark">
Fee
</Heading>
<Text size="sm">{prettyTezAmount(String(params.suggestedFeeMutez))}</Text>
<Text size="sm">{prettyTezAmount(String(params.totalCost))}</Text>
</Flex>
</ModalBody>

Expand Down
2 changes: 1 addition & 1 deletion src/components/AccountCard/ApproveExecuteForm/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApproveOrExecute } from "../../../utils/tezos/types";
import { MultisigOperation } from "../../../utils/multisig/types";
import { ContractAddress, ImplicitAddress } from "../../../types/Address";

export type ParamsWithFee = ApproveExecuteParams & { suggestedFeeMutez: number };
export type ParamsWithFee = ApproveExecuteParams & { totalCost: number };

export type ApproveExecuteParams = {
type: ApproveOrExecute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useApproveOrExecuteModdal = () => {
setIsLoading(true);
try {
const pk = getPk(params.signer.pkh);
const { suggestedFeeMutez } = await estimateMultisigApproveOrExecute(
const { totalCost } = await estimateMultisigApproveOrExecute(
{
type: params.type,
contract: params.multisigAddress,
Expand All @@ -28,7 +28,7 @@ export const useApproveOrExecuteModdal = () => {
params.signer.pkh,
network
);
onOpen({ ...params, suggestedFeeMutez });
onOpen({ ...params, totalCost });
} catch (error: any) {
console.warn("Failed simulation", error);
toast({ title: "Failed simulation", description: error.message, status: "warning" });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("<MultisigPendingCard/>", () => {
address: parseImplicitPkh("tz1UNer1ijeE9ndjzSszRduR3CzX49hoBUB3"),
};
fakeTezosUtils.estimateMultisigApproveOrExecute.mockResolvedValue({
suggestedFeeMutez: 33,
totalCost: 33,
} as Estimate);

fakeTezosUtils.approveOrExecuteMultisigOperation.mockResolvedValue({
Expand Down Expand Up @@ -144,7 +144,7 @@ describe("<MultisigPendingCard/>", () => {
address: parseImplicitPkh("tz1UNer1ijeE9ndjzSszRduR3CzX49hoBUB3"),
};
fakeTezosUtils.estimateMultisigApproveOrExecute.mockResolvedValue({
suggestedFeeMutez: 33,
totalCost: 33,
} as Estimate);

fakeTezosUtils.approveOrExecuteMultisigOperation.mockResolvedValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("<MultisigPendingAccordion />", () => {

it("should display multisig executable tez operations", async () => {
fakeTezosUtils.estimateMultisigApproveOrExecute.mockResolvedValue({
suggestedFeeMutez: 33,
totalCost: 33,
} as Estimate);
const m: Multisig = {
address: parseContractPkh("KT1Jr2UdC6boStHUrVyFYoxArKfNr1CDiYxK"),
Expand Down
8 changes: 4 additions & 4 deletions src/components/sendForm/SendForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe("<SendForm />", () => {

fakeTezosUtils.estimateBatch.mockResolvedValue([
{
suggestedFeeMutez: 12345,
totalCost: 12345,
} as Estimate,
]);

Expand Down Expand Up @@ -785,7 +785,7 @@ describe("<SendForm />", () => {

test("User can acomplish a tez proposal", async () => {
fakeTezosUtils.estimateMultisigPropose.mockResolvedValueOnce({
suggestedFeeMutez: 12345,
totalCost: 12345,
} as Estimate);
fakeTezosUtils.proposeMultisigLambda.mockResolvedValueOnce({
hash: "mockHash",
Expand Down Expand Up @@ -841,7 +841,7 @@ describe("<SendForm />", () => {

test("User can acomplish an FA2 proposal", async () => {
fakeTezosUtils.estimateMultisigPropose.mockResolvedValueOnce({
suggestedFeeMutez: 12345,
totalCost: 12345,
} as Estimate);
fakeTezosUtils.proposeMultisigLambda.mockResolvedValueOnce({
hash: "mockHash",
Expand Down Expand Up @@ -902,7 +902,7 @@ describe("<SendForm />", () => {
},
};
fakeTezosUtils.estimateMultisigPropose.mockResolvedValueOnce({
suggestedFeeMutez: 12345,
totalCost: 12345,
} as Estimate);
fakeTezosUtils.proposeMultisigLambda.mockResolvedValueOnce({
hash: "mockHash",
Expand Down
2 changes: 1 addition & 1 deletion src/components/sendForm/util/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const makeMultisigProposalSimulation = async (
};

const getTotalFee = (estimate: Estimate[] | Estimate) =>
String(Array.isArray(estimate) ? sumEstimations(estimate) : estimate.suggestedFeeMutez);
String(Array.isArray(estimate) ? sumEstimations(estimate) : estimate.totalCost);

export const makeSimulation = async (
operation: FormOperations,
Expand Down
8 changes: 4 additions & 4 deletions src/integration/tezos.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe("Tezos utils", () => {
);

for (let i = 0; i < ghostnetResult.length; i += 1) {
expect(ghostnetResult[i]).toHaveProperty("suggestedFeeMutez");
expect(ghostnetResult[i]).toHaveProperty("totalCost");
}
});

Expand All @@ -251,8 +251,8 @@ describe("Tezos utils", () => {

expect(mainnetResult).toHaveLength(2);

expect(mainnetResult[0]).toHaveProperty("suggestedFeeMutez");
expect(mainnetResult[1]).toHaveProperty("suggestedFeeMutez");
expect(mainnetResult[0]).toHaveProperty("totalCost");
expect(mainnetResult[1]).toHaveProperty("totalCost");
});

test("Batch estimation works with batches containing delegations on mainnet", async () => {
Expand All @@ -270,7 +270,7 @@ describe("Tezos utils", () => {

expect(mainnetResult).toHaveLength(1);

expect(mainnetResult[0]).toHaveProperty("suggestedFeeMutez");
expect(mainnetResult[0]).toHaveProperty("totalCost");
});

test("Batch estimation fails with insuficient funds on mainnet", async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/mocks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const setBatchEstimationPerTransaction = (
) => {
fakeEstimateBatch.mockImplementation(async (transactions: any[]) => {
return transactions.map(_ => ({
suggestedFeeMutez: mutez,
totalCost: mutez,
})) as Estimate[];
});
};
6 changes: 3 additions & 3 deletions src/multisig/multisigSandbox2.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe("multisig Sandbox", () => {
await devAccount0.publicKeyHash(),
TezosNetwork.GHOSTNET
);
expect(proposeEstimate).toHaveProperty("suggestedFeeMutez");
expect(proposeEstimate).toHaveProperty("totalCost");

const proposeResponse = await proposeMultisigLambda(
{ contract: MULTISIG_GHOSTNET_1, lambdaActions },
Expand Down Expand Up @@ -122,7 +122,7 @@ describe("multisig Sandbox", () => {
await devAccount1.publicKeyHash(),
TezosNetwork.GHOSTNET
);
expect(approveEstimate).toHaveProperty("suggestedFeeMutez");
expect(approveEstimate).toHaveProperty("totalCost");

const approveResponse = await approveOrExecuteMultisigOperation(
{
Expand Down Expand Up @@ -151,7 +151,7 @@ describe("multisig Sandbox", () => {
await devAccount1.publicKeyHash(),
TezosNetwork.GHOSTNET
);
expect(executeEstimate).toHaveProperty("suggestedFeeMutez");
expect(executeEstimate).toHaveProperty("totalCost");

const executeResponse = await approveOrExecuteMultisigOperation(
{
Expand Down
46 changes: 15 additions & 31 deletions src/utils/store/assetsSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,7 @@ describe("Assets reducer", () => {

describe("Batch", () => {
test("Adding operations to batch starts an estimation and updates the given account's batch with the result", async () => {
const mockEstimations = [
{ suggestedFeeMutez: "323" },
{ suggestedFeeMutez: "423" },
{ suggestedFeeMutez: "523" },
];
const mockEstimations = [{ totalCost: "323" }, { totalCost: "423" }, { totalCost: "523" }];

estimateBatchMock.mockResolvedValueOnce(mockEstimations);

Expand All @@ -366,15 +362,15 @@ describe("Assets reducer", () => {
isSimulating: false,
items: [
{
fee: mockEstimations[0].suggestedFeeMutez,
fee: mockEstimations[0].totalCost,
operation: transfers[0],
},
{
fee: mockEstimations[1].suggestedFeeMutez,
fee: mockEstimations[1].totalCost,
operation: transfers[1],
},
{
fee: mockEstimations[2].suggestedFeeMutez,
fee: mockEstimations[2].totalCost,
operation: transfers[2],
},
],
Expand All @@ -383,7 +379,7 @@ describe("Assets reducer", () => {
});

test("Batches can be cleared for a given account", async () => {
const mockEstimations = [{ suggestedFeeMutez: "323" }];
const mockEstimations = [{ totalCost: "323" }];

estimateBatchMock.mockResolvedValueOnce(mockEstimations);

Expand All @@ -401,7 +397,7 @@ describe("Assets reducer", () => {
isSimulating: false,
items: [
{
fee: mockEstimations[0].suggestedFeeMutez,
fee: mockEstimations[0].totalCost,
operation: transfers[0],
},
],
Expand Down Expand Up @@ -437,11 +433,7 @@ describe("Assets reducer", () => {
});

test("Running a concurrent estimation for a given account is not possible", async () => {
const mockEstimations = [
{ suggestedFeeMutez: "323" },
{ suggestedFeeMutez: "423" },
{ suggestedFeeMutez: "523" },
];
const mockEstimations = [{ totalCost: "323" }, { totalCost: "423" }, { totalCost: "523" }];

estimateBatchMock.mockResolvedValueOnce(mockEstimations);
estimateBatchMock.mockResolvedValueOnce(mockEstimations);
Expand All @@ -467,15 +459,15 @@ describe("Assets reducer", () => {
isSimulating: false,
items: [
{
fee: mockEstimations[0].suggestedFeeMutez,
fee: mockEstimations[0].totalCost,
operation: transfers[0],
},
{
fee: mockEstimations[1].suggestedFeeMutez,
fee: mockEstimations[1].totalCost,
operation: transfers[1],
},
{
fee: mockEstimations[2].suggestedFeeMutez,
fee: mockEstimations[2].totalCost,
operation: transfers[2],
},
],
Expand All @@ -484,11 +476,7 @@ describe("Assets reducer", () => {
});

test("You can't add an empty list of operations to a batch", async () => {
const mockEstimations = [
{ suggestedFeeMutez: "323" },
{ suggestedFeeMutez: "423" },
{ suggestedFeeMutez: "523" },
];
const mockEstimations = [{ totalCost: "323" }, { totalCost: "423" }, { totalCost: "523" }];

estimateBatchMock.mockResolvedValueOnce(mockEstimations);

Expand All @@ -507,11 +495,7 @@ describe("Assets reducer", () => {
});

test("Batch can't be cleared for a given account if simulation is ongoing for a given account", async () => {
const mockEstimations = [
{ suggestedFeeMutez: "323" },
{ suggestedFeeMutez: "423" },
{ suggestedFeeMutez: "523" },
];
const mockEstimations = [{ totalCost: "323" }, { totalCost: "423" }, { totalCost: "523" }];

estimateBatchMock.mockResolvedValueOnce(mockEstimations);
estimateBatchMock.mockResolvedValueOnce(mockEstimations);
Expand Down Expand Up @@ -543,16 +527,16 @@ describe("Assets reducer", () => {
operation: mockTezTransfer(3),
},
{
fee: mockEstimations[0].suggestedFeeMutez,
fee: mockEstimations[0].totalCost,
operation: transfers[0],
},

{
fee: mockEstimations[1].suggestedFeeMutez,
fee: mockEstimations[1].totalCost,
operation: transfers[1],
},
{
fee: mockEstimations[2].suggestedFeeMutez,
fee: mockEstimations[2].totalCost,
operation: transfers[2],
},
],
Expand Down
4 changes: 2 additions & 2 deletions src/views/batch/batchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getBatchSubtotal = (ops: Operation[]) => {
export const sumEstimations = (es: Estimate[]) => {
return es
.reduce((acc, curr) => {
return acc.plus(curr.suggestedFeeMutez);
return acc.plus(curr.totalCost);
}, new BigNumber(0))
.toNumber();
};
Expand All @@ -43,7 +43,7 @@ export const operationsToBatchItems = async (
const estimations = await estimateBatch(operations, pkh, pk, network);
const items = zip(operations, estimations).map(([o, e]) => {
return {
fee: String(e.suggestedFeeMutez),
fee: String(e.totalCost),
operation: o,
};
});
Expand Down