-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathButtonTransfer.js
More file actions
136 lines (128 loc) · 3.82 KB
/
ButtonTransfer.js
File metadata and controls
136 lines (128 loc) · 3.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React, { useEffect, useState } from "react";
import Button from "../../../components/Button";
import { submitFormData } from "../../../store/actions/transactions/delegationTransfer";
import { useDispatch, useSelector } from "react-redux";
import { keplrSubmit } from "../../../store/actions/transactions/keplr";
import {
setTxIno,
setTxName
} from "../../../store/actions/transactions/common";
import { LOGIN_INFO } from "../../../constants/localStorage";
import {
msgSendTypeUrl,
RedeemTokenizedSharesMsg,
TokenizedSharesRewardsMsg,
TokenizeSharesTransferMsg
} from "../../../utils/protoMsgHelper";
import { DefaultChainInfo } from "../../../config";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { trimWhiteSpaces } from "../../../utils/scripts";
import { handleDelegationTransferModal } from "../../../store/actions/transactions/delegationTransfer";
function SendMsg(fromAddress, toAddress, balance) {
return {
typeUrl: msgSendTypeUrl,
value: MsgSend.fromPartial({
fromAddress: trimWhiteSpaces(fromAddress),
toAddress: trimWhiteSpaces(toAddress),
amount: balance
})
};
}
const ButtonTransfer = ({ tokenizedShares, rewardList }) => {
const dispatch = useDispatch();
const loginInfo = JSON.parse(localStorage.getItem(LOGIN_INFO));
const toAddress = useSelector((state) => state.delegationTransfer.toAddress);
const onClick = () => {
const messages = getMessage();
console.log(messages, "messages-transfer")
dispatch(submitFormData(messages));
};
const disable = tokenizedShares.length <= 0 || toAddress.value === "";
const getMessage = () => {
let messages = [];
// const ledgerApp = localStorage.getItem("ledgerAppName");
// if(loginInfo && loginInfo.loginMode === "keplr" || ledgerApp !== "Persistence"){
rewardList.forEach((item) => {
const msg = TokenizedSharesRewardsMsg(item.owner,item.recordId);
messages.push(msg);
});
let blcList = [];
tokenizedShares.forEach((item) => {
const blc = {
amount: (item.amount * DefaultChainInfo.uTokenValue).toFixed(0),
denom: item.denom
};
blcList.push(blc);
const msg = TokenizeSharesTransferMsg(
item.recordId,
loginInfo.address,
toAddress.value
);
messages.push(msg);
});
const sendMsg = SendMsg(
loginInfo && loginInfo.address,
toAddress.value,
blcList
);
messages.push(sendMsg);
return messages;
// } else {
// let blcList = [];
// tokenizedShares.forEach((item) => {
// const blc = {
// amount: (item.amount * DefaultChainInfo.uTokenValue).toFixed(0),
// denom: item.denom
// };
// blcList.push(blc);
// });
// const sendMsg = SendMsg(
// loginInfo && loginInfo.address,
// toAddress.value,
// blcList
// );
// messages.push(sendMsg);
// return messages;
// }
};
const onClickKeplr = () => {
const messages = getMessage();
dispatch(
setTxIno({
value: {
modal: handleDelegationTransferModal(false),
data: {
message: "",
memo: ""
}
}
})
);
dispatch(
setTxName({
value: {
name: "transfer-shares"
}
})
);
dispatch(keplrSubmit(messages));
};
return (
<div className="buttons">
<div className="button-section">
<Button
className="button button-primary"
type="button"
disable={disable}
value="Transfer Shares"
onClick={
loginInfo && loginInfo.loginMode === "keplr"
? onClickKeplr
: onClick
}
/>
</div>
</div>
);
};
export default ButtonTransfer;