Skip to content

Commit

Permalink
removed unnecessary calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkachez committed Jan 29, 2025
1 parent 0f754b9 commit 261470e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
1 change: 0 additions & 1 deletion examples/neon-transfer-vue/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const handleEvmNetworkSelect = (event: any): any => {
formStore.setTokenList();
formStore.setCurrentSplToken('');
transactionStore.setSignature({});
walletsStore.setTokenBalance();
};
const handleTransferDirection = () => {
const isSolanaDirection = transferDirection.value.direction === 'solana';
Expand Down
49 changes: 26 additions & 23 deletions examples/neon-transfer-vue/src/stores/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ export const useFormStore = defineStore('form', {
setTimeout(() => resolve(), timestamp);
});
},
async initWalletUpdate() {
const walletSore = useWalletsStore();

if (this.currentSplToken?.symbol === 'SOL') {
const solana = await walletSore.getSolanaBalance();
walletSore.updateWalletBalance({
...walletSore.walletBalance,
solana
});
} else {
const neon = await walletSore.getNeonBalance();
walletSore.updateWalletBalance({
...walletSore.walletBalance,
neon
});
}
},
async initTransfer() {
//TODO: Refactor this!!!
//Get rid of the repeated code
Expand Down Expand Up @@ -185,22 +202,14 @@ export const useFormStore = defineStore('form', {
}

const transactionFunctions = {
NEON: () => {
console.log('asfsaf =', {
provider: toRaw(web3Store.ethersProvider as JsonRpcProvider),
from: walletSore.neonWallet.address,
to: NEON_TRANSFER_CONTRACT_DEVNET,
solanaWallet: walletSore.solanaWallet.publicKey,
amount: this.amount
});
return neonNeonTransactionEthers({
NEON: () =>
neonNeonTransactionEthers({
provider: toRaw(web3Store.ethersProvider as JsonRpcProvider),
from: walletSore.neonWallet.address,
to: NEON_TRANSFER_CONTRACT_DEVNET,
solanaWallet: walletSore.solanaWallet.publicKey,
amount: this.amount
});
},
}),
SOL: () =>
neonNeonTransactionEthers({
provider: toRaw(web3Store.ethersProvider as JsonRpcProvider),
Expand All @@ -209,22 +218,14 @@ export const useFormStore = defineStore('form', {
solanaWallet: walletSore.solanaWallet.publicKey,
amount: this.amount
}),
DEFAULT: () => {
console.log('object = ', {
provider: toRaw(web3Store.ethersProvider as JsonRpcProvider),
neonWallet: walletSore.neonWallet.address,
associatedToken,
splToken: this.currentSplToken,
amount: this.amount
});
return createMintNeonTransactionEthers({
DEFAULT: () =>
createMintNeonTransactionEthers({
provider: toRaw(web3Store.ethersProvider as JsonRpcProvider),
neonWallet: walletSore.neonWallet.address,
associatedToken,
splToken: this.currentSplToken,
amount: this.amount
});
}
})
//Used for all ERC20 token transaction (including wSOL)
};

Expand All @@ -237,7 +238,9 @@ export const useFormStore = defineStore('form', {
}

await this.handleDelay(1e3);
await walletSore.setWalletBalance();
if (['SOL', 'NEON'].includes(this.currentSplToken?.symbol)) {
await this.initWalletUpdate();
}
await walletSore.getTokenBalance(this.currentSplToken);
await this.handleDelay(5e3);

Expand Down
15 changes: 9 additions & 6 deletions examples/neon-transfer-vue/src/stores/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export const useWalletsStore = defineStore('wallets', {
this.isLoading = true;
this.setSolanaWallet();
this.setSolanaWalletSigner();
await this.setTokenBalance();
await this.setWalletBalance();
this.isLoading = false;
},
Expand Down Expand Up @@ -96,7 +95,6 @@ export const useWalletsStore = defineStore('wallets', {
async getTokenBalance(token: SPLToken) {
const formStore = useFormStore();
formStore.setIsPendingTokenChange(true);

try {
switch (token.symbol) {
case 'NEON': {
Expand All @@ -118,10 +116,15 @@ export const useWalletsStore = defineStore('wallets', {
break;
}
case 'SOL': {
const neon = await this.getNeonBalance();
const balance =
formStore.transferDirection.direction === 'solana'
? await this.getSolanaBalance()
: await this.getMintTokenBalance();

formStore.setError(false);
this.updateTokenBalance({ ...this.tokenBalance, neon });
const newBalance = { ...this.tokenBalance };
newBalance[formStore.transferDirection.direction] = balance;
this.updateTokenBalance(newBalance);
break;
}
case 'wSOL': {
Expand All @@ -131,14 +134,14 @@ export const useWalletsStore = defineStore('wallets', {
this.solanaWallet.publicKey
);

const transaction =
const balance =
formStore.transferDirection.direction === 'solana'
? await this.getSolanaBalance(associatedToken)
: await this.getMintTokenBalance();

formStore.setError(false);
const newBalance = { ...this.tokenBalance };
newBalance[formStore.transferDirection.direction] = transaction;
newBalance[formStore.transferDirection.direction] = balance;
this.updateTokenBalance(newBalance);
break;
}
Expand Down

0 comments on commit 261470e

Please sign in to comment.