Skip to content

Commit

Permalink
perf: do not create new sdk instance on invite claim
Browse files Browse the repository at this point in the history
  • Loading branch information
CedrikNikita committed May 7, 2024
1 parent bd88b60 commit 1a314ef
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions src/composables/invites.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {
AE_AMOUNT_FORMATS,
AeSdk,
Encoded,
Node,
} from '@aeternity/aepp-sdk';
import type { AccountAddress, IInvite } from '@/types';
import { STORAGE_KEYS } from '@/constants';
Expand All @@ -11,7 +9,7 @@ import { getAccountFromSecret } from '@/protocols/aeternity/helpers';
import migrateInvitesVuexToComposable from '@/migrations/006-invites-vuex-to-composable';
import { useStorageRef } from './storageRef';
import { useModals } from './modals';
import { useNetworks } from './networks';
import { useAeSdk } from './aeSdk';

const invites = useStorageRef<IInvite[]>(
[],
Expand All @@ -24,7 +22,7 @@ const invites = useStorageRef<IInvite[]>(
);

export function useInvites() {
const { activeNetwork } = useNetworks();
const { getDryAeSdk } = useAeSdk();
const { openDefaultModal } = useModals();

function addInvite(secretKey: Buffer) {
Expand All @@ -44,25 +42,21 @@ export function useInvites() {
amount = '0',
isMax = false,
}: { secretKey: Buffer; recipientId: AccountAddress; amount?: string; isMax: boolean }) {
const aeSdk = new AeSdk({
nodes: [{
name: activeNetwork.value.name,
instance: new Node(activeNetwork.value.protocols.aeternity.nodeUrl),
}],
accounts: [getAccountFromSecret(secretKey)],
});
const dryAeSdk = await getDryAeSdk();
if (!isMax) {
await aeSdk.spend(
await dryAeSdk.spend(
amount,
recipientId as Encoded.AccountAddress,
// @ts-ignore
{ denomination: AE_AMOUNT_FORMATS.AE },
{
denomination: AE_AMOUNT_FORMATS.AE,
onAccount: getAccountFromSecret(secretKey),
},
);
} else {
await aeSdk.transferFunds(
await dryAeSdk.transferFunds(
1, // Decimal percentage, 1 = 100%
recipientId as Encoded.AccountAddress,
{ verify: false },
{ onAccount: getAccountFromSecret(secretKey) },
);
}
}
Expand Down

0 comments on commit 1a314ef

Please sign in to comment.