Skip to content

Commit dbc4186

Browse files
Merge pull request #1902 from gabrielbazan7/ref/token-transfer
[REF] WC handle sol token transfers
2 parents c6b57f1 + 6d53f73 commit dbc4186

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/store/wallet/effects/send/send.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,11 +512,11 @@ export const buildTxDetails =
512512
} else {
513513
const decodedInstructions = request.decodedInstructions;
514514
const computUnitLimit =
515-
decodedInstructions?.setComputeUnitLimit[0].computeUnitLimit;
515+
decodedInstructions?.setComputeUnitLimit?.[0].computeUnitLimit;
516516
const computeUnitPrice =
517-
decodedInstructions?.setComputeUnitPrice[0].microLamports;
517+
decodedInstructions?.setComputeUnitPrice?.[0].microLamports;
518518
const isPriority =
519-
decodedInstructions?.setComputeUnitPrice[0].priority;
519+
decodedInstructions?.setComputeUnitPrice?.[0].priority;
520520
const SOL_BASE_FEE_LAMPORTS = 5000; // default base fee in lamports
521521
if (computUnitLimit && computeUnitPrice && isPriority) {
522522
fee =
@@ -1084,11 +1084,12 @@ const buildTransactionProposal =
10841084
} else {
10851085
const decodedInstructions = request.decodedInstructions;
10861086
const computUnitLimit =
1087-
decodedInstructions?.setComputeUnitLimit[0].computeUnitLimit;
1087+
decodedInstructions?.setComputeUnitLimit?.[0]
1088+
.computeUnitLimit;
10881089
const computeUnitPrice =
1089-
decodedInstructions?.setComputeUnitPrice[0].microLamports;
1090+
decodedInstructions?.setComputeUnitPrice?.[0].microLamports;
10901091
const isPriority =
1091-
decodedInstructions?.setComputeUnitPrice[0].priority;
1092+
decodedInstructions?.setComputeUnitPrice?.[0].priority;
10921093
const SOL_BASE_FEE_LAMPORTS = 5000; // default base fee in lamports
10931094
if (computUnitLimit && computeUnitPrice && isPriority) {
10941095
txp.fee =

src/utils/helper-methods.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,11 +913,24 @@ export const processSolanaSwapRequest =
913913
0,
914914
);
915915
currency = 'sol';
916+
} else if (
917+
instructions?.[instructionKeys.TRANSFER_CHECKED_TOKEN]?.length > 0
918+
) {
919+
const checkedTokenTransfer = instructions[
920+
instructionKeys.TRANSFER_CHECKED_TOKEN
921+
] as TransferSolInstruction[];
922+
mainToAddress = checkedTokenTransfer[0].destination;
923+
amount = checkedTokenTransfer.reduce(
924+
(sum, transfer) => sum + Number(transfer.amount),
925+
0,
926+
);
927+
tokenAddress = checkedTokenTransfer[0].mint!;
928+
currency = (await getSolanaTokenInfo(tokenAddress)).symbol?.toLowerCase();
916929
}
917930

918931
dispatch(
919932
LogActions.debug(
920-
`amount: ${amount},mainToAddress: ${mainToAddress}, currency: ${currency}, tokenAddress: ${tokenAddress}`,
933+
`amount: ${amount}, mainToAddress: ${mainToAddress}, currency: ${currency}, tokenAddress: ${tokenAddress}`,
921934
),
922935
);
923936

src/utils/sol-transaction-instruction.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export interface TransferSolInstruction {
33
currency: 'SOL';
44
destination: string;
55
source: string;
6+
authority?: string;
7+
mint?: string;
68
}
79

810
export interface AdvanceNonceAccountInstruction {

0 commit comments

Comments
 (0)