Skip to content

Commit 196256c

Browse files
committed
chore: first, use an optional parameter
Ticket: WIN-5679
1 parent fd831a2 commit 196256c

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

modules/sdk-coin-sol/src/lib/ataInitializationBuilder.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ export class AtaInitializationBuilder extends TransactionBuilder {
116116
validateOwnerAddress(recipient.ownerAddress);
117117
const token = getSolTokenFromTokenName(recipient.tokenName);
118118
let tokenAddress: string;
119-
if (token) {
120-
tokenAddress = token.tokenAddress;
121-
} else if (recipient.tokenAddress) {
119+
if (recipient.tokenAddress) {
122120
tokenAddress = recipient.tokenAddress;
121+
} else if (token) {
122+
tokenAddress = token.tokenAddress;
123123
} else {
124124
throw new BuildTransactionError('Invalid transaction: invalid token name, got: ' + recipient.tokenName);
125125
}
@@ -148,12 +148,12 @@ export class AtaInitializationBuilder extends TransactionBuilder {
148148
const token = getSolTokenFromTokenName(recipient.tokenName);
149149
let tokenAddress: string;
150150
let programId: string;
151-
if (token) {
152-
tokenAddress = token.tokenAddress;
153-
programId = token.programId;
154-
} else if (recipient.tokenAddress && recipient.programId) {
151+
if (recipient.tokenAddress && recipient.programId) {
155152
tokenAddress = recipient.tokenAddress;
156153
programId = recipient.programId;
154+
} else if (token) {
155+
tokenAddress = token.tokenAddress;
156+
programId = token.programId;
157157
} else {
158158
throw new BuildTransactionError('Invalid transaction: invalid token name, got: ' + recipient.tokenName);
159159
}

modules/sdk-coin-sol/src/lib/solInstructionFactory.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ function tokenTransferInstruction(data: TokenTransfer): TransactionInstruction[]
162162
let tokenAddress: string;
163163
let programId: string | undefined;
164164
let decimalPlaces: number;
165-
if (token) {
165+
if (data.params.tokenAddress && data.params.decimalPlaces) {
166+
tokenAddress = data.params.tokenAddress;
167+
decimalPlaces = data.params.decimalPlaces;
168+
programId = data.params.programId;
169+
} else if (token) {
166170
assert(token instanceof SolCoin);
167171
tokenAddress = token.tokenAddress;
168172
decimalPlaces = token.decimalPlaces;
169173
programId = token.programId;
170-
} else if (data.params.tokenAddress && data.params.decimalPlaces) {
171-
tokenAddress = data.params.tokenAddress;
172-
decimalPlaces = data.params.decimalPlaces;
173-
programId = data.params.programId;
174174
} else {
175175
throw new Error('Invalid token name, got:' + data.params.tokenName);
176176
}

modules/sdk-coin-sol/src/lib/tokenTransferBuilder.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ export class TokenTransferBuilder extends TransactionBuilder {
9696
validateOwnerAddress(recipient.ownerAddress);
9797
const token = getSolTokenFromTokenName(recipient.tokenName);
9898
let tokenAddress: string;
99-
if (token) {
100-
tokenAddress = token.tokenAddress;
101-
} else if (recipient.tokenAddress) {
99+
if (recipient.tokenAddress) {
102100
tokenAddress = recipient.tokenAddress;
101+
} else if (token) {
102+
tokenAddress = token.tokenAddress;
103103
} else {
104104
throw new BuildTransactionError('Invalid token name, got: ' + recipient.tokenName);
105105
}
@@ -119,16 +119,16 @@ export class TokenTransferBuilder extends TransactionBuilder {
119119
let tokenName: string;
120120
let programId: string | undefined;
121121
let decimals: number | undefined;
122-
if (coin) {
123-
tokenAddress = coin.tokenAddress;
124-
tokenName = coin.name;
125-
programId = coin.programId;
126-
decimals = coin.decimalPlaces;
127-
} else if (sendParams.tokenAddress) {
122+
if (sendParams.tokenAddress && sendParams.programId && sendParams.decimalPlaces) {
128123
tokenAddress = sendParams.tokenAddress;
129124
tokenName = sendParams.tokenName;
130125
programId = sendParams.programId;
131126
decimals = sendParams.decimalPlaces;
127+
} else if (coin) {
128+
tokenAddress = coin.tokenAddress;
129+
tokenName = coin.name;
130+
programId = coin.programId;
131+
decimals = coin.decimalPlaces;
132132
} else {
133133
throw new Error(`Could not determine token information for ${sendParams.tokenName}`);
134134
}
@@ -157,14 +157,14 @@ export class TokenTransferBuilder extends TransactionBuilder {
157157
let tokenAddress: string;
158158
let tokenName: string;
159159
let programId: string | undefined;
160-
if (coin) {
161-
tokenName = coin.name;
162-
tokenAddress = coin.tokenAddress;
163-
programId = coin.programId;
164-
} else if (recipient.tokenAddress) {
160+
if (recipient.tokenAddress && recipient.programId) {
165161
tokenName = recipient.tokenName;
166162
tokenAddress = recipient.tokenAddress;
167163
programId = recipient.programId;
164+
} else if (coin) {
165+
tokenName = coin.name;
166+
tokenAddress = coin.tokenAddress;
167+
programId = coin.programId;
168168
} else {
169169
throw new Error(`Could not determine token information for ${recipient.tokenName}`);
170170
}

modules/sdk-coin-sol/src/lib/transferBuilderV2.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ export class TransferBuilderV2 extends TransactionBuilder {
112112
validateOwnerAddress(recipient.ownerAddress);
113113
const token = getSolTokenFromTokenName(recipient.tokenName);
114114
let tokenAddress;
115-
if (token) {
116-
tokenAddress = token.tokenAddress;
117-
} else if (recipient.tokenAddress) {
115+
if (recipient.tokenAddress) {
118116
tokenAddress = recipient.tokenAddress;
117+
} else if (token) {
118+
tokenAddress = token.tokenAddress;
119119
}
120120

121121
if (!tokenAddress) {
@@ -138,16 +138,16 @@ export class TransferBuilderV2 extends TransactionBuilder {
138138
let tokenName: string;
139139
let programId: string | undefined;
140140
let decimals: number | undefined;
141-
if (coin) {
142-
tokenName = coin.name;
143-
tokenAddress = coin.tokenAddress;
144-
decimals = coin.decimalPlaces;
145-
programId = coin.programId;
146-
} else if (sendParams.tokenAddress) {
141+
if (sendParams.tokenAddress && sendParams.programId && sendParams.decimalPlaces) {
147142
tokenName = sendParams.tokenName;
148143
tokenAddress = sendParams.tokenAddress;
149144
decimals = sendParams.decimalPlaces;
150145
programId = sendParams.programId;
146+
} else if (coin) {
147+
tokenName = coin.name;
148+
tokenAddress = coin.tokenAddress;
149+
decimals = coin.decimalPlaces;
150+
programId = coin.programId;
151151
} else {
152152
throw new Error(`Could not determine token information for ${sendParams.tokenName}`);
153153
}
@@ -187,14 +187,14 @@ export class TransferBuilderV2 extends TransactionBuilder {
187187
let tokenAddress: string;
188188
let tokenName: string;
189189
let programId: string | undefined;
190-
if (coin) {
191-
tokenName = coin.name;
192-
tokenAddress = coin.tokenAddress;
193-
programId = coin.programId;
194-
} else if (recipient.tokenAddress) {
190+
if (recipient.tokenAddress && recipient.programId) {
195191
tokenName = recipient.tokenName;
196192
tokenAddress = recipient.tokenAddress;
197193
programId = recipient.programId;
194+
} else if (coin) {
195+
tokenName = coin.name;
196+
tokenAddress = coin.tokenAddress;
197+
programId = coin.programId;
198198
} else {
199199
throw new Error(`Could not determine token information for ${recipient.tokenName}`);
200200
}

0 commit comments

Comments
 (0)