| 6 | "": "// MIT License: https://github.com/linear-protocol/linear-bos-components/blob/main/LICENSE\\\\n\\\\nconst accountId = props.accountId || context.accountId;\\\\nconst LiNEAR_DECIMALS = 24;\\\\nconst subgraphApiUrl =\\\\n context.networkId === \\\\\\\"mainnet\\\\\\\"\\\\n ? \\\\\\\"https://api.studio.thegraph.com/query/76854/linear/version/latest\\\\\\\"\\\\n : \\\\\\\"https://api.studio.thegraph.com/query/76854/linear-testnet/version/latest\\\\\\\";\\\\n\\\\nconst { config, onLoad } = props;\\\\nif (!config) {\\\\n return \\\\\\\"Component cannot be loaded. Missing `config` props\\\\\\\";\\\\n}\\\\n\\\\nfunction getLinearPrice() {\\\\n return Big(Near.view(config.contractId, \\\\\\\"ft_price\\\\\\\", \\\\\\\"{}\\\\\\\") ?? \\\\\\\"0\\\\\\\").div(\\\\n Big(10).pow(LiNEAR_DECIMALS)\\\\n );\\\\n}\\\\n\\\\nfunction querySubgraph(query, variables) {\\\\n const res = fetch(subgraphApiUrl, {\\\\n method: \\\\\\\"POST\\\\\\\",\\\\n headers: {\\\\n \\\\\\\"Content-Type\\\\\\\": \\\\\\\"application/json\\\\\\\",\\\\n },\\\\n body: JSON.stringify({\\\\n query,\\\\n variables,\\\\n }),\\\\n });\\\\n if (res && res.ok) {\\\\n return res.body;\\\\n } else {\\\\n return {};\\\\n }\\\\n}\\\\n\\\\nfunction queryStakingData(accountId, excludingFees) {\\\\n const { data } = querySubgraph(`\\\\n {\\\\n users (first: 1, where: {id: \\\\\\\"${accountId}\\\\\\\"} ){\\\\n firstStakingTime\\\\n mintedLinear\\\\n stakedNear\\\\n unstakedLinear\\\\n unstakeReceivedNear\\\\n feesPaid\\\\n transferedInShares\\\\n transferedInValue\\\\n transferedOutShares\\\\n transferedOutValue\\\\n }\\\\n }\\\\n `);\\\\n if (!data) {\\\\n return undefined;\\\\n }\\\\n const user = data.users[0];\\\\n if (!user) {\\\\n return undefined;\\\\n }\\\\n\\\\n const linearPrice = getLinearPrice();\\\\n if (Number(linearPrice) === 0) {\\\\n return undefined;\\\\n }\\\\n\\\\n const {\\\\n firstStakingTime,\\\\n stakedNear,\\\\n mintedLinear,\\\\n unstakedLinear,\\\\n unstakeReceivedNear,\\\\n feesPaid,\\\\n transferedInShares,\\\\n transferedInValue,\\\\n transferedOutShares,\\\\n transferedOutValue,\\\\n } = user;\\\\n\\\\n const transferIn = linearPrice\\\\n .mul(transferedInShares)\\\\n .minus(transferedInValue);\\\\n const transferOut = linearPrice\\\\n .mul(transferedOutShares)\\\\n .minus(transferedOutValue);\\\\n const netTransfer = transferIn.minus(transferOut);\\\\n\\\\n const currentLinear = Big(mintedLinear).minus(unstakedLinear);\\\\n const rewards = currentLinear\\\\n .mul(linearPrice)\\\\n .minus(stakedNear)\\\\n .plus(unstakeReceivedNear)\\\\n .plus(netTransfer);\\\\n\\\\n return {\\\\n // turn nanoseconds into milliseconds\\\\n firstStakingTime: firstStakingTime\\\\n ? parseInt(firstStakingTime / 1_000_000)\\\\n : undefined,\\\\n // add fees if necessary\\\\n stakingRewards: (excludingFees ? rewards : rewards.plus(feesPaid)).toFixed(\\\\n 0\\\\n ),\\\\n };\\\\n}\\\\n\\\\nif (onLoad) {\\\\n const data = queryStakingData(accountId);\\\\n if (data) {\\\\n onLoad(data);\\\\n }\\\\n}\\\\n\\\\nreturn <div style={{ display: \\\\\\\"none\\\\\\\" }} />;\\\\n", |