Skip to content

Commit

Permalink
cleanup unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
petersalomonsen committed Dec 6, 2023
1 parent 01ccd58 commit ede36f7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions src/lib/components/ConfirmTransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export default function ConfirmTransactions(props) {
const contractId = transactions[0].contractName;
const isSignedIntoContract = await near.isSignedIntoContract(contractId);

console.log('is signed in?', isSignedIntoContract);

const widgetContractPermission = await cache.asyncLocalStorageGet(StorageDomain, {
widgetSrc,
contractId,
Expand All @@ -55,13 +53,11 @@ export default function ConfirmTransactions(props) {
console.log(widgetContractPermission);

const dontAskForConfirmation = (isSignedIntoContract && widgetContractPermission && widgetContractPermission[transactions[0].methodName])
? true : false;
? true : false;

console.log('auto send?', dontAskForConfirmation);
setDontAskForConfirmation(dontAskForConfirmation);

if (dontAskForConfirmation) {
console.log('sending transactions', transactions);
setLoading(true);
const result = await near.sendTransactions(transactions);
console.log(result);
Expand All @@ -80,8 +76,6 @@ export default function ConfirmTransactions(props) {
setDontAskAgainChecked(!dontAskAgainChecked);
};

console.log('dont confirm? ', dontAskForConfirmation, transactions.length);

if (dontAskForConfirmation) {
const transaction = transactions[0];
return (<Modal size="xs" centered show={show} onHide={onHide}>
Expand Down
1 change: 0 additions & 1 deletion src/lib/data/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ class Cache {
console.error("Key deserialization failed", stringKey);
return;
}

if (
key.action === Action.ViewCall &&
key.contractId === near.config.contractName &&
Expand Down
32 changes: 11 additions & 21 deletions src/lib/data/near.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,12 @@ function getKeyStoreForContract(contractId) {
);
}

function clearKeyStoreForContract(contractId) {
getKeyStoreForContract(contractId).clear();
}


async function createWalletConnectionForContract(near, contractId) {
const keyStore = getKeyStoreForContract(contractId);
console.log('looking up wallet', contractId);

const selector = await near.selector;
if (selector) {
const wallet = await selector.wallet();
console.log('found wallet', wallet);
const _near = await nearAPI.connect({
keyStore,
walletUrl: wallet.metadata.walletUrl,
Expand Down Expand Up @@ -184,31 +178,28 @@ async function sendTransactions(near, functionCalls) {
const transactions = [];
let currentTotalGas = Big(0);
functionCalls.forEach(
({ contractName, methodName, args, gas, deposit, actions }) => {
({ contractName, methodName, args, gas, deposit }) => {
const newTotalGas = currentTotalGas.add(gas);

const action = functionCallCreator(
methodName,
args,
gas.toFixed(0),
deposit.toFixed(0)
);
if (
transactions[transactions.length - 1]?.receiverId !== contractName ||
newTotalGas.gt(MaxGasPerTransaction)
) {
transactions.push({
receiverId: contractName,
actions: actions ?? [],
actions: [],
});
currentTotalGas = gas;
} else {
currentTotalGas = newTotalGas;
}
if (!actions) {
const action = functionCallCreator(
methodName,
args,
gas.toFixed(0),
deposit.toFixed(0)
);

transactions[transactions.length - 1].actions.push(action);
}
transactions[transactions.length - 1].actions.push(action);
}
);
return await wallet.signAndSendTransactions({ transactions });
Expand Down Expand Up @@ -393,8 +384,7 @@ async function _initNear({

_near.isSignedIntoContract = async (contractId) => isSignedIntoContract(_near, contractId);
_near.signInAndSetPendingTransaction = async (transaction) => signInAndSetPendingTransaction(_near, transaction);
_near.clearKeyStoreForContract = (contractId) => clearKeyStoreForContract(contractId);


_near.contract = setupContract(_near, config.contractName, {
viewMethods: [
"storage_balance_of",
Expand Down

0 comments on commit ede36f7

Please sign in to comment.