Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit c7f9c9c

Browse files
committed
refactor: 💡 replace all SQ syn awaits with newer function
1 parent 840ab95 commit c7f9c9c

File tree

4 files changed

+29
-43
lines changed

4 files changed

+29
-43
lines changed

src/__tests__/sdk/assets/manageNft.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515

1616
import { TestFactory } from '~/helpers';
1717
import { createNftCollection } from '~/sdk/assets/createNftCollection';
18+
import { awaitMiddlewareSynced } from '~/util';
1819

1920
let factory: TestFactory;
2021

@@ -54,20 +55,20 @@ describe('manageNft', () => {
5455

5556
receiver = await sdk.identities.getIdentity({ did: receiverDid });
5657

57-
const portfolioProc = await sdk.identities.createPortfolio({ name: 'NFT portfolio' });
58+
const portfolioTx = await sdk.identities.createPortfolio({ name: 'NFT portfolio' });
5859

59-
const venueProc = await sdk.settlements.createVenue({
60+
const venueTx = await sdk.settlements.createVenue({
6061
description: 'test exchange',
6162
type: VenueType.Exchange,
6263
});
6364

64-
const pauseProc = await collection.compliance.requirements.pause();
65+
const pauseTx = await collection.compliance.requirements.pause();
6566

66-
const batchProc = await sdk.createTransactionBatch({
67-
transactions: [portfolioProc, venueProc, pauseProc] as const,
67+
const batchTx = await sdk.createTransactionBatch({
68+
transactions: [portfolioTx, venueTx, pauseTx] as const,
6869
});
6970

70-
[portfolio, venue] = await batchProc.run();
71+
[portfolio, venue] = await batchTx.run();
7172

7273
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
7374
holder = (await sdk.getSigningIdentity())!;
@@ -96,7 +97,7 @@ describe('manageNft', () => {
9697
});
9798

9899
it('should issue an Nft', async () => {
99-
const issueProc = await collection.issue({
100+
const issueTx = await collection.issue({
100101
metadata: [
101102
{ type: MetadataType.Local, id: new BigNumber(1), value: 'https://example.com/nft/1' },
102103
{
@@ -107,13 +108,13 @@ describe('manageNft', () => {
107108
],
108109
});
109110

110-
nft = await issueProc.run();
111+
nft = await issueTx.run();
111112

112113
expect(nft.id).toEqual(new BigNumber(1));
113114
});
114115

115116
it('should allow holder to transfer NFTs between portfolios', async () => {
116-
const moveProc = await defaultPortfolio.moveFunds({
117+
const moveTx = await defaultPortfolio.moveFunds({
117118
to: portfolio,
118119
items: [
119120
{
@@ -123,7 +124,7 @@ describe('manageNft', () => {
123124
],
124125
});
125126

126-
await moveProc.run();
127+
await moveTx.run();
127128

128129
const [defaultCollections, portfolioCollections] = await Promise.all([
129130
defaultPortfolio.getCollections(),
@@ -152,7 +153,7 @@ describe('manageNft', () => {
152153
});
153154

154155
it('should let the holder send instructions with an NFT', async () => {
155-
const instructionProc = await sdk.settlements.addInstruction({
156+
const instructionTx = await sdk.settlements.addInstruction({
156157
venueId: venue.id,
157158
legs: [
158159
{
@@ -164,12 +165,9 @@ describe('manageNft', () => {
164165
],
165166
});
166167

167-
const middlewareSynced = () =>
168-
new Promise((resolve) => instructionProc.onProcessedByMiddleware(resolve));
168+
instruction = await instructionTx.run();
169169

170-
instruction = await instructionProc.run();
171-
172-
await middlewareSynced();
170+
await awaitMiddlewareSynced(instructionTx, sdk);
173171
});
174172

175173
it('should return legs for an instruction when they contain an NFT', async () => {
@@ -188,8 +186,8 @@ describe('manageNft', () => {
188186
});
189187

190188
it('should allow the receiver to accept an NFT settlement', async () => {
191-
const affirmProc = await instruction.affirm({}, { signingAccount: receiverAddress });
192-
await affirmProc.run();
189+
const affirmTx = await instruction.affirm({}, { signingAccount: receiverAddress });
190+
await affirmTx.run();
193191

194192
const receiverPortfolio = await receiver.portfolios.getPortfolio();
195193

@@ -209,7 +207,7 @@ describe('manageNft', () => {
209207
});
210208

211209
it('should allow the issuer to redeem an NFT', async () => {
212-
const createNftProc = await collection.issue({
210+
const createNftTx = await collection.issue({
213211
metadata: [
214212
{ type: MetadataType.Local, id: new BigNumber(1), value: 'https://example.com/nft/1' },
215213
{
@@ -220,10 +218,10 @@ describe('manageNft', () => {
220218
],
221219
});
222220

223-
const redeemNft = await createNftProc.run();
221+
const redeemNft = await createNftTx.run();
224222

225-
const redeemProc = await redeemNft.redeem();
223+
const redeemTx = await redeemNft.redeem();
226224

227-
expect(redeemProc.run()).resolves.not.toThrow();
225+
expect(redeemTx.run()).resolves.not.toThrow();
228226
});
229227
});

src/sdk/identities/customClaims.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '@polymeshassociation/polymesh-sdk/types';
88
import assert from 'node:assert';
99

10-
import { randomString } from '~/util';
10+
import { awaitMiddlewareSynced, randomString } from '~/util';
1111

1212
export const manageCustomClaims = async (
1313
sdk: Polymesh,
@@ -28,12 +28,9 @@ export const manageCustomClaims = async (
2828
{ signingAccount }
2929
);
3030

31-
const middlewareSyncedOnClaimType = () =>
32-
new Promise((resolve) => registerCustomClaimTypeTx.onProcessedByMiddleware(resolve));
33-
3431
const customClaimTypeId = await registerCustomClaimTypeTx.run();
3532

36-
await middlewareSyncedOnClaimType();
33+
await awaitMiddlewareSynced(registerCustomClaimTypeTx, sdk);
3734

3835
const registeredCustomClaimTypes = await sdk.claims.getAllCustomClaimTypes();
3936

@@ -71,14 +68,11 @@ export const manageCustomClaims = async (
7168
{ signingAccount }
7269
);
7370

74-
const middlewareSyncedOnAddClaim = () =>
75-
new Promise((resolve) => addClaimTx.onProcessedByMiddleware(resolve));
76-
7771
await addClaimTx.run();
7872

7973
assert(addClaimTx.isSuccess, 'Should be able to add a custom claim');
8074

81-
await middlewareSyncedOnAddClaim();
75+
await awaitMiddlewareSynced(addClaimTx, sdk);
8276

8377
const revokeClaimTx = await sdk.claims.revokeClaims(
8478
{ claims: [customClaim] },

src/sdk/identities/portfolioCustody.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Polymesh } from '@polymeshassociation/polymesh-sdk';
22
import assert from 'node:assert';
33

4+
import { awaitMiddlewareSynced } from '~/util';
5+
46
/*
57
This script showcases Portfolio's Custodian related functionality. It:
68
- Creates a Portfolio
@@ -45,9 +47,6 @@ export const portfolioCustody = async (sdk: Polymesh, custodianDid: string): Pro
4547
// The custodian needs to accept the created authorization
4648
const acceptTx = await authRequest.accept({ signingAccount: custodianAccount });
4749

48-
const middlewareSynced = () =>
49-
new Promise((resolve) => acceptTx.onProcessedByMiddleware(resolve));
50-
5150
await acceptTx.run();
5251
assert(acceptTx.isSuccess);
5352

@@ -62,7 +61,7 @@ export const portfolioCustody = async (sdk: Polymesh, custodianDid: string): Pro
6261
);
6362
assert(!isCustodiedByOwner, `DID ${identity.did} should no longer be be the custodian`);
6463

65-
await middlewareSynced();
64+
await awaitMiddlewareSynced(acceptTx, sdk);
6665

6766
// The custodian can get all non owned portfolios where they are the custodian - note there are pagination options
6867
const custodiedPortfolios = await custodian.portfolios.getCustodiedPortfolios();

src/sdk/settlements/tradeOffChainAssets.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import assert from 'node:assert';
88

99
import { createVenue } from '~/sdk/settlements/createVenue';
10+
import { awaitMiddlewareSynced } from '~/util';
1011

1112
interface OffChainLegInfo {
1213
ticker: string;
@@ -71,13 +72,10 @@ export const tradeOffChainAssets = async (
7172
memo: 'Some message',
7273
});
7374

74-
const middlewareSynced = () =>
75-
new Promise((resolve) => addInstructionTx.onProcessedByMiddleware(resolve));
76-
7775
const instruction = await addInstructionTx.run();
7876
assert(addInstructionTx.isSuccess, 'add instruction should succeed');
7977

80-
await middlewareSynced();
78+
await awaitMiddlewareSynced(addInstructionTx, sdk);
8179

8280
const details = await instruction.details();
8381
assert(details.memo, 'the instruction should have a memo');
@@ -109,13 +107,10 @@ export const tradeOffChainAssets = async (
109107
receipts: offChainReceipts,
110108
});
111109

112-
const middlewareAffirmationsSynced = () =>
113-
new Promise((resolve) => affirmWithReceiptTx.onProcessedByMiddleware(resolve));
114-
115110
await affirmWithReceiptTx.run();
116111
assert(affirmWithReceiptTx.isSuccess);
117112

118-
await middlewareAffirmationsSynced();
113+
await awaitMiddlewareSynced(affirmWithReceiptTx, sdk);
119114

120115
// Fetch and verify off chain affirmations
121116
const offChainAffirmations = await instruction.getOffChainAffirmations();

0 commit comments

Comments
 (0)