File tree Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Expand file tree Collapse file tree 2 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ if (state.page === "stake") {
174
174
{ state . tabName === "stake" && (
175
175
< Widget
176
176
src = { `${ config . ownerId } /widget/LiNEAR.Stake` }
177
- props = { { config, nearBalance, updateAccountInfo } }
177
+ props = { { config, nearBalance, linearBalance , updateAccountInfo } }
178
178
/>
179
179
) }
180
180
{ state . tabName === "unstake" && (
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ function formatAmount(a) {
35
35
36
36
/** common lib end */
37
37
const nearBalance = props . nearBalance || "-" ;
38
+ const linearBalance = props . linearBalance || "-" ;
38
39
39
40
/** events start */
40
41
const onChange = ( e ) => {
@@ -127,13 +128,29 @@ const onClickStake = async () => {
127
128
} else setInputError ( "" ) ;
128
129
return ;
129
130
}
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 ) ;
137
154
138
155
// update account balances
139
156
if ( props . updateAccountInfo ) {
You can’t perform that action at this time.
0 commit comments