Skip to content

Commit 021167d

Browse files
authored
Merge pull request #553 from enkryptcom/feat/fail-dropped-jupiter-transactions
feat: fail dropped jupiter transactions
2 parents 7f0f6c3 + 216798b commit 021167d

File tree

16 files changed

+238
-135
lines changed

16 files changed

+238
-135
lines changed

packages/extension/src/libs/activity-state/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class ActivityState {
6161
this.getActivityId(options),
6262
);
6363
}
64+
6465
async updateActivity(
6566
activity: Activity,
6667
options: ActivityOptions,
@@ -75,24 +76,29 @@ class ActivityState {
7576
});
7677
await this.setActivitiesById(clone, this.getActivityId(options));
7778
}
79+
7880
async setCacheTime(options: ActivityOptions): Promise<void> {
7981
await this.#storage.set(this.getActivityCacheId(options), {
8082
[STORAGE_KEY]: new Date().getTime(),
8183
});
8284
}
85+
8386
async getCacheTime(options: ActivityOptions): Promise<number> {
8487
const cacheTime: Record<string, number> = await this.#storage.get(
8588
this.getActivityCacheId(options),
8689
);
8790
if (!cacheTime || !cacheTime[STORAGE_KEY]) return 0;
8891
return cacheTime[STORAGE_KEY];
8992
}
93+
9094
async getAllActivities(options: ActivityOptions): Promise<Activity[]> {
9195
return this.getActivitiesById(this.getActivityId(options));
9296
}
97+
9398
async deleteAllActivities(options: ActivityOptions): Promise<void> {
9499
this.setActivitiesById([], this.getActivityId(options));
95100
}
101+
96102
private async setActivitiesById(
97103
activities: Activity[],
98104
id: string,
@@ -101,6 +107,7 @@ class ActivityState {
101107
[STORAGE_KEY]: activities,
102108
});
103109
}
110+
104111
private async getActivitiesById(id: string): Promise<Activity[]> {
105112
const allStates: Record<string, Activity[]> = await this.#storage.get(id);
106113
if (!allStates || !allStates[STORAGE_KEY]) return [];

packages/extension/src/providers/solana/libs/api.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,48 @@ class API implements ProviderAPIInterface {
2323
return getSolAddress(pubkey);
2424
}
2525

26-
async init(): Promise<void> {}
26+
async init(): Promise<void> { }
27+
28+
/**
29+
* Returns null if the transaction hasn't been received by the node
30+
* or has been dropped
31+
*/
2732
async getTransactionStatus(hash: string): Promise<SOLRawInfo | null> {
28-
return this.web3
29-
.getTransaction(hash, {
30-
maxSupportedTransactionVersion: 0,
31-
commitment: 'confirmed',
32-
})
33-
.then(tx => {
34-
if (!tx) return null;
35-
const retVal: SOLRawInfo = {
36-
blockNumber: tx.slot,
37-
timestamp: tx.blockTime,
38-
transactionHash: hash,
39-
status: tx.meta?.err ? false : true,
40-
};
41-
return retVal;
42-
});
33+
const tx = await this.web3.getTransaction(hash, {
34+
maxSupportedTransactionVersion: 0,
35+
commitment: 'confirmed',
36+
})
37+
38+
if (!tx) {
39+
// Transaction hasn't been picked up by the node
40+
// (maybe it's too soon, or maybe node is behind, or maybe it's been dropped)
41+
return null;
42+
}
43+
44+
const retVal: SOLRawInfo = {
45+
blockNumber: tx.slot,
46+
timestamp: tx.blockTime,
47+
transactionHash: hash,
48+
status: tx.meta?.err ? false : true,
49+
};
50+
51+
return retVal;
4352
}
53+
4454
async getBalance(pubkey: string): Promise<string> {
4555
const balance = await this.web3.getBalance(
4656
new PublicKey(this.getAddress(pubkey)),
4757
);
4858
return numberToHex(balance);
4959
}
60+
5061
async broadcastTx(rawtx: string): Promise<boolean> {
5162
return this.web3
5263
.sendRawTransaction(hexToBuffer(rawtx))
5364
.then(() => true)
5465
.catch(() => false);
5566
}
67+
5668
getTokenInfo = async (contractAddress: string): Promise<SPLTokenInfo> => {
5769
interface TokenDetails {
5870
address: string;

packages/extension/src/types/activity.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ enum ActivityStatus {
9595
pending = 'pending',
9696
success = 'success',
9797
failed = 'failed',
98+
dropped = 'dropped',
9899
}
99100

100101
enum ActivityType {
@@ -121,13 +122,13 @@ interface Activity {
121122
status: ActivityStatus;
122123
type: ActivityType;
123124
rawInfo?:
124-
| EthereumRawInfo
125-
| SubstrateRawInfo
126-
| SubscanExtrinsicInfo
127-
| BTCRawInfo
128-
| SwapRawInfo
129-
| KadenaRawInfo
130-
| SOLRawInfo;
125+
| EthereumRawInfo
126+
| SubstrateRawInfo
127+
| SubscanExtrinsicInfo
128+
| BTCRawInfo
129+
| SwapRawInfo
130+
| KadenaRawInfo
131+
| SOLRawInfo;
131132
}
132133

133134
export {

packages/extension/src/ui/action/views/network-activity/components/network-activity-transaction.vue

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
<p>
3838
<span
3939
class="network-activity__transaction-info-status"
40-
:class="{ error: activity.status === ActivityStatus.failed }"
40+
:class="{
41+
error: activity.status === ActivityStatus.failed,
42+
dropped: activity.status === ActivityStatus.dropped,
43+
}"
4144
>{{ status }}</span
4245
>
4346
<transaction-timer
@@ -86,7 +89,10 @@
8689
<p>
8790
<span
8891
class="network-activity__transaction-info-status"
89-
:class="{ error: activity.status === ActivityStatus.failed }"
92+
:class="{
93+
error: activity.status === ActivityStatus.failed,
94+
dropped: activity.status === ActivityStatus.dropped,
95+
}"
9096
>{{ status }}</span
9197
>
9298
<transaction-timer
@@ -242,30 +248,32 @@ onMounted(() => {
242248
if (
243249
props.activity.status === ActivityStatus.success &&
244250
props.activity.isIncoming
245-
)
251+
) {
246252
status.value =
247253
props.activity.type === ActivityType.transaction ? 'Received' : 'Swapped';
248-
else if (
254+
} else if (
249255
props.activity.status === ActivityStatus.success &&
250256
!props.activity.isIncoming
251-
)
257+
) {
252258
status.value =
253259
props.activity.type === ActivityType.transaction ? 'Sent' : 'Swapped';
254-
else if (
260+
} else if (
255261
props.activity.status === ActivityStatus.pending &&
256262
props.activity.isIncoming
257-
)
263+
) {
258264
status.value =
259265
props.activity.type === ActivityType.transaction
260266
? 'Receiving'
261267
: 'Swapping';
262-
else if (
268+
} else if (
263269
props.activity.status === ActivityStatus.pending &&
264270
!props.activity.isIncoming
265-
)
271+
) {
266272
status.value =
267273
props.activity.type === ActivityType.transaction ? 'Sending' : 'Swapping';
268-
else {
274+
} else if (props.activity.status === ActivityStatus.dropped) {
275+
status.value = 'Dropped';
276+
} else {
269277
status.value = 'Failed';
270278
}
271279
});
@@ -335,6 +343,9 @@ onMounted(() => {
335343
.error {
336344
color: @error;
337345
}
346+
.dropped {
347+
/* TODO: Consider different color */
348+
}
338349
}
339350
}
340351

0 commit comments

Comments
 (0)