-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6206 from StricaHQ/bugfix/cardano-stake-btn
fix canStake method
- Loading branch information
Showing
4 changed files
with
45 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"ledger-live-desktop": patch | ||
"@ledgerhq/live-common": patch | ||
--- | ||
|
||
Cardano stake button fix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 27 additions & 34 deletions
61
libs/ledger-live-common/src/families/cardano/logic.unit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,44 @@ | ||
import BigNumber from "bignumber.js"; | ||
import { canStake } from "./logic"; | ||
import { canStake, isAlreadyStaking } from "./logic"; | ||
import { CardanoAccount } from "./types"; | ||
|
||
describe("canStake", () => { | ||
it("should return false when acc delegation data is incomplete", () => { | ||
it("should return false when acc not present", () => { | ||
const noResourcesAcc = {} as CardanoAccount; | ||
expect(canStake(noResourcesAcc)).toEqual(false); | ||
const noDelegationAcc = { | ||
cardanoResources: {}, | ||
balance: new BigNumber(1), | ||
} as CardanoAccount; | ||
expect(canStake(noDelegationAcc)).toEqual(false); | ||
const noPoolIdAcc = { | ||
balance: new BigNumber(1), | ||
cardanoResources: { | ||
delegation: {}, | ||
}, | ||
} as CardanoAccount; | ||
expect(canStake(noPoolIdAcc)).toEqual(false); | ||
}); | ||
|
||
it("should return false when acc already has a delegation but no funds", () => { | ||
const poolIdNoFundsAcc = { | ||
it("should return false when acc has no funds", () => { | ||
const accWithNoFunds = { | ||
balance: new BigNumber(0), | ||
cardanoResources: { | ||
delegation: { | ||
poolId: "helloiamapoolid", | ||
}, | ||
}, | ||
} as CardanoAccount; | ||
expect(canStake(poolIdNoFundsAcc)).toEqual(false); | ||
expect(canStake(accWithNoFunds)).toEqual(false); | ||
}); | ||
|
||
it("should return false when acc has no funds", () => { | ||
const noResourcesAcc = { balance: new BigNumber(0) } as CardanoAccount; | ||
expect(canStake(noResourcesAcc)).toEqual(false); | ||
it("should return true when acc has funds", () => { | ||
const accWithFunds = { | ||
balance: new BigNumber(1), | ||
} as CardanoAccount; | ||
expect(canStake(accWithFunds)).toEqual(true); | ||
}); | ||
}); | ||
|
||
it("should return true when acc already has a delegation and funds", () => { | ||
const poolIdAcc = { | ||
balance: new BigNumber(1), | ||
cardanoResources: { | ||
delegation: { | ||
poolId: "helloiamapoolid", | ||
}, | ||
}, | ||
describe("isAlreadyStaking", () => { | ||
it("should return false when acc isn't delegating", () => { | ||
const noResourcesAcc = {} as CardanoAccount; | ||
expect(isAlreadyStaking(noResourcesAcc)).toEqual(false); | ||
const noDelegationAcc = { | ||
cardanoResources: {}, | ||
} as CardanoAccount; | ||
expect(isAlreadyStaking(noDelegationAcc)).toEqual(false); | ||
const noPoolIdAcc = { cardanoResources: { delegation: {} } } as CardanoAccount; | ||
expect(isAlreadyStaking(noPoolIdAcc)).toEqual(false); | ||
}); | ||
|
||
it("should return true when acc is delegating", () => { | ||
const noResourcesAcc = { | ||
cardanoResources: { delegation: { poolId: "itspoolid" } }, | ||
} as CardanoAccount; | ||
expect(canStake(poolIdAcc)).toEqual(true); | ||
expect(isAlreadyStaking(noResourcesAcc)).toEqual(true); | ||
}); | ||
}); |