Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a5743a3

Browse files
authoredMay 6, 2023
feat: automatically register LiNEAR token to web wallet (#16)
1 parent 14cc24f commit a5743a3

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed
 

‎src/LiNEAR.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ if (state.page === "stake") {
174174
{state.tabName === "stake" && (
175175
<Widget
176176
src={`${config.ownerId}/widget/LiNEAR.Stake`}
177-
props={{ config, nearBalance, updateAccountInfo }}
177+
props={{ config, nearBalance, linearBalance, updateAccountInfo }}
178178
/>
179179
)}
180180
{state.tabName === "unstake" && (

‎src/LiNEAR/Stake.jsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function formatAmount(a) {
3535

3636
/** common lib end */
3737
const nearBalance = props.nearBalance || "-";
38+
const linearBalance = props.linearBalance || "-";
3839

3940
/** events start */
4041
const onChange = (e) => {
@@ -127,13 +128,29 @@ const onClickStake = async () => {
127128
} else setInputError("");
128129
return;
129130
}
130-
Near.call(
131-
config.contractId,
132-
"deposit_and_stake",
133-
{},
134-
undefined,
135-
Big(state.inputValue).mul(Big(10).pow(NEAR_DECIMALS)).toFixed(0)
136-
);
131+
132+
const stake = {
133+
contractName: config.contractId,
134+
methodName: "deposit_and_stake",
135+
deposit: Big(state.inputValue).mul(Big(10).pow(NEAR_DECIMALS)).toFixed(0),
136+
args: {},
137+
};
138+
const registerFt = {
139+
contractName: config.contractId,
140+
methodName: "ft_balance_of",
141+
args: {
142+
account_id: accountId,
143+
},
144+
};
145+
const txs = [stake];
146+
// If account has no LiNEAR, we assume she/he needs to register LiNEAR token.
147+
// By adding a `ft_balance_of` function call, the NEAR indexer will automatically
148+
// add LiNEAR token into caller's NEAR wallet token list.
149+
if (Number(linearBalance) === 0) {
150+
txs.push(registerFt);
151+
}
152+
153+
Near.call(txs);
137154

138155
// update account balances
139156
if (props.updateAccountInfo) {

0 commit comments

Comments
 (0)
Please sign in to comment.