Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fail dropped jupiter transactions #553

Merged
merged 7 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/extension/src/libs/activity-state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ActivityState {
this.getActivityId(options),
);
}

async updateActivity(
activity: Activity,
options: ActivityOptions,
Expand All @@ -75,24 +76,29 @@ class ActivityState {
});
await this.setActivitiesById(clone, this.getActivityId(options));
}

async setCacheTime(options: ActivityOptions): Promise<void> {
await this.#storage.set(this.getActivityCacheId(options), {
[STORAGE_KEY]: new Date().getTime(),
});
}

async getCacheTime(options: ActivityOptions): Promise<number> {
const cacheTime: Record<string, number> = await this.#storage.get(
this.getActivityCacheId(options),
);
if (!cacheTime || !cacheTime[STORAGE_KEY]) return 0;
return cacheTime[STORAGE_KEY];
}

async getAllActivities(options: ActivityOptions): Promise<Activity[]> {
return this.getActivitiesById(this.getActivityId(options));
}

async deleteAllActivities(options: ActivityOptions): Promise<void> {
this.setActivitiesById([], this.getActivityId(options));
}

NickKelly1 marked this conversation as resolved.
Show resolved Hide resolved
private async setActivitiesById(
activities: Activity[],
id: string,
Expand All @@ -101,6 +107,7 @@ class ActivityState {
[STORAGE_KEY]: activities,
});
}

private async getActivitiesById(id: string): Promise<Activity[]> {
const allStates: Record<string, Activity[]> = await this.#storage.get(id);
if (!allStates || !allStates[STORAGE_KEY]) return [];
Expand Down
44 changes: 28 additions & 16 deletions packages/extension/src/providers/solana/libs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,48 @@ class API implements ProviderAPIInterface {
return getSolAddress(pubkey);
}

async init(): Promise<void> {}
async init(): Promise<void> { }

/**
* Returns null if the transaction hasn't been received by the node
* or has been dropped
*/
async getTransactionStatus(hash: string): Promise<SOLRawInfo | null> {
return this.web3
.getTransaction(hash, {
maxSupportedTransactionVersion: 0,
commitment: 'confirmed',
})
.then(tx => {
if (!tx) return null;
const retVal: SOLRawInfo = {
blockNumber: tx.slot,
timestamp: tx.blockTime,
transactionHash: hash,
status: tx.meta?.err ? false : true,
};
return retVal;
});
const tx = await this.web3.getTransaction(hash, {
maxSupportedTransactionVersion: 0,
commitment: 'confirmed',
})

if (!tx) {
// Transaction hasn't been picked up by the node
// (maybe it's too soon, or maybe node is behind, or maybe it's been dropped)
return null;
}

const retVal: SOLRawInfo = {
blockNumber: tx.slot,
timestamp: tx.blockTime,
transactionHash: hash,
status: tx.meta?.err ? false : true,
};

return retVal;
}
NickKelly1 marked this conversation as resolved.
Show resolved Hide resolved

async getBalance(pubkey: string): Promise<string> {
const balance = await this.web3.getBalance(
new PublicKey(this.getAddress(pubkey)),
);
return numberToHex(balance);
}

async broadcastTx(rawtx: string): Promise<boolean> {
return this.web3
.sendRawTransaction(hexToBuffer(rawtx))
.then(() => true)
.catch(() => false);
}

getTokenInfo = async (contractAddress: string): Promise<SPLTokenInfo> => {
interface TokenDetails {
address: string;
Expand Down
15 changes: 8 additions & 7 deletions packages/extension/src/types/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ enum ActivityStatus {
pending = 'pending',
success = 'success',
failed = 'failed',
dropped = 'dropped',
}

enum ActivityType {
Expand All @@ -121,13 +122,13 @@ interface Activity {
status: ActivityStatus;
type: ActivityType;
rawInfo?:
| EthereumRawInfo
| SubstrateRawInfo
| SubscanExtrinsicInfo
| BTCRawInfo
| SwapRawInfo
| KadenaRawInfo
| SOLRawInfo;
| EthereumRawInfo
| SubstrateRawInfo
| SubscanExtrinsicInfo
| BTCRawInfo
| SwapRawInfo
| KadenaRawInfo
| SOLRawInfo;
}

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
<p>
<span
class="network-activity__transaction-info-status"
:class="{ error: activity.status === ActivityStatus.failed }"
:class="{
error: activity.status === ActivityStatus.failed,
dropped: activity.status === ActivityStatus.dropped,
}"
>{{ status }}</span
>
<transaction-timer
Expand Down Expand Up @@ -88,7 +91,10 @@
<p>
<span
class="network-activity__transaction-info-status"
:class="{ error: activity.status === ActivityStatus.failed }"
:class="{
error: activity.status === ActivityStatus.failed,
dropped: activity.status === ActivityStatus.dropped,
}"
>{{ status }}</span
>
<transaction-timer
Expand Down Expand Up @@ -163,30 +169,32 @@ onMounted(() => {
if (
props.activity.status === ActivityStatus.success &&
props.activity.isIncoming
)
) {
status.value =
props.activity.type === ActivityType.transaction ? 'Received' : 'Swapped';
else if (
} else if (
props.activity.status === ActivityStatus.success &&
!props.activity.isIncoming
)
) {
status.value =
props.activity.type === ActivityType.transaction ? 'Sent' : 'Swapped';
else if (
} else if (
props.activity.status === ActivityStatus.pending &&
props.activity.isIncoming
)
) {
status.value =
props.activity.type === ActivityType.transaction
? 'Receiving'
: 'Swapping';
else if (
} else if (
props.activity.status === ActivityStatus.pending &&
!props.activity.isIncoming
)
) {
status.value =
props.activity.type === ActivityType.transaction ? 'Sending' : 'Swapping';
else {
} else if (props.activity.status === ActivityStatus.dropped) {
status.value = 'Dropped';
} else {
status.value = 'Failed';
}
});
Expand Down Expand Up @@ -256,6 +264,9 @@ onMounted(() => {
.error {
color: @error;
}
.dropped {
/* TODO: Consider different color */
}
}
}

Expand Down
Loading