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

Ana/send claim rewards amount to extension #3736

Merged
merged 8 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions changes/ana_send-claim-rewards-amount-to-extension
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Changed] [#3736](https://github.com/cosmos/lunie/pull/3736) Now ModalWithdrawRewards returns the claimed rewards amount in transactionData and sends it to the extension @Bitcoinera
7 changes: 6 additions & 1 deletion src/ActionModal/components/ActionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ export default {
submitType: this.selectedSignMethod,
password: this.password
}
const txMetadata = {
faboweb marked this conversation as resolved.
Show resolved Hide resolved
...feeProperties,
displayedProperties:
this.title === "Claim Rewards" ? properties.amounts : null
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
displayedProperties:
this.title === "Claim Rewards" ? properties.amounts : null
}
displayedProperties: {
amounts: properties.amounts
}
}


try {
await this.$apollo.queries.overview.refetch()
Expand All @@ -753,7 +758,7 @@ export default {
type,
memo,
properties,
feeProperties
txMetadata
faboweb marked this conversation as resolved.
Show resolved Hide resolved
)

const { hash } = hashResult
Expand Down
22 changes: 15 additions & 7 deletions src/ActionModal/components/ModalWithdrawRewards.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,15 @@ export default {
computed: {
...mapGetters([`address`, `network`, `stakingDenom`]),
transactionData() {
if (!this.claimedReward) return {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this for? will this break if claimedReward is not there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied from the other components 🤷‍♀

Yes, it would break but it would in any case. I can just get rid of it

By the way, we should merge this now that luniehq/lunie-browser-extension#179 is in, since otherwise it will break sowieso with the first claim rewards transaction

return {
type: transaction.WITHDRAW
type: transaction.WITHDRAW,
amounts: [
{
amount: this.claimedReward.amount,
denom: this.claimedReward.denom
}
]
}
},
totalRewards() {
Expand All @@ -88,14 +95,15 @@ export default {
}
},
claimedReward() {
if (this.denom && this.rewards && this.rewards.length > 0) {
if (this.rewards && this.rewards.length > 0) {
// we return the staking denom reward if it has any. Otherwise, we return the first reward from the other tokens
const rewardsGreaterThanZero = this.rewards.filter(
reward => reward.amount > 0
)
return (
rewardsGreaterThanZero.find(reward => reward.denom === this.denom) ||
rewardsGreaterThanZero[0]
rewardsGreaterThanZero.find(
reward => reward.denom === this.stakingDenom
) || rewardsGreaterThanZero[0]
)
} else {
return ""
Expand All @@ -108,15 +116,15 @@ export default {
if (this.balances && this.balances.length > 0) {
const nonZeroBalances = this.balances.filter(({ amount }) => amount > 0)
const stakingDenomBalance = nonZeroBalances.find(
({ denom }) => denom === this.denom
({ denom }) => denom === this.stakingDenom
)
return stakingDenomBalance
? stakingDenomBalance.denom
: nonZeroBalances.length > 0
? nonZeroBalances[0].denom
: this.denom
: this.stakingDenom
} else {
return this.denom
return this.stakingDenom
}
}
},
Expand Down
11 changes: 9 additions & 2 deletions src/ActionModal/utils/ActionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,19 @@ export default class ActionManager {
transactionProperties,
txMetaData
) {
const { gasEstimate, gasPrice, submitType, password } = txMetaData
const {
gasEstimate,
gasPrice,
submitType,
password,
displayedProperties
} = txMetaData
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😉

const signer = await getSigner(config, submitType, {
address: userAddress,
password,
network: networkId,
networkType
networkType,
displayedProperties
})

const messageMetadata = {
Expand Down
9 changes: 7 additions & 2 deletions src/ActionModal/utils/signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function signQueue(submitType = "") {
export async function getSigner(
config,
signingType = "",
{ address, password, network, networkType }
{ address, password, network, networkType, displayedProperties }
) {
if (signingType === `local`) {
const { getStoredWallet } = await import("@lunie/cosmos-keys")
Expand All @@ -35,7 +35,12 @@ export async function getSigner(
}
} else if (signingType === `extension`) {
return signMessage => {
return signWithExtension(signMessage, address, network)
return signWithExtension(
signMessage,
address,
network,
displayedProperties
)
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/scripts/extension-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,16 @@ export const getSignQueue = async () => {
export const signWithExtension = async (
signMessage,
senderAddress,
network
network,
displayedProperties
) => {
const { signature, publicKey } = await sendAsyncMessageToContentScript({
type: "LUNIE_SIGN_REQUEST",
payload: {
signMessage,
senderAddress,
network
network,
displayedProperties
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ describe(`ModalWithdrawRewards`, () => {
describe("Submission Data for Delegating", () => {
it("should return correct transaction data for delegating", () => {
expect(wrapper.vm.transactionData).toEqual({
type: "MsgWithdrawDelegationReward"
type: "MsgWithdrawDelegationReward",
amounts: [
{
amount: 1,
denom: "STAKE"
}
]
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ exports[`ModalWithdrawRewards should show the withdraw rewards modal 1`] = `
id="modal-withdraw-rewards"
notifymessage="[object Object]"
rewards="[object Object],[object Object]"
selecteddenom=""
selecteddenom="STAKE"
submissionerrorprefix="Withdrawal failed"
title="Claim Rewards"
transactiondata="[object Object]"
Expand Down