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

chore: remove discover mode from hub adapter #966

Merged
merged 3 commits into from
Dec 31, 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
10 changes: 5 additions & 5 deletions queue-manager/rango-preset/src/actions/checkStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { httpService } from '../services';
import { notifier } from '../services/eventEmitter';
import {
getCurrentBlockchainOf,
getCurrentNamespaceOf,
getNextStep,
getRelatedWallet,
getScannerUrl,
Expand Down Expand Up @@ -90,13 +90,13 @@ async function checkTransactionStatus({
if (updatedTxHash !== txId) {
currentStep.executedTransactionId =
updatedTxHash || currentStep.executedTransactionId;
const currentStepBlockchain = getCurrentBlockchainOf(swap, currentStep);
const currentStepNamespace = getCurrentNamespaceOf(swap, currentStep);
let explorerUrl: string | undefined;
const blockchainsMetaNotEmpty = !!Object.keys(meta.blockchains).length;
if (blockchainsMetaNotEmpty) {
explorerUrl = getScannerUrl(
currentStep.executedTransactionId,
currentStepBlockchain,
currentStepNamespace.network,
meta.blockchains
);
}
Expand Down Expand Up @@ -314,13 +314,13 @@ async function checkApprovalStatus({
if (updatedTxHash !== txId) {
currentStep.executedTransactionId =
updatedTxHash || currentStep.executedTransactionId;
const currentStepBlockchain = getCurrentBlockchainOf(swap, currentStep);
const currentStepNamespace = getCurrentNamespaceOf(swap, currentStep);
let explorerUrl: string | undefined;
const blockchainsMetaNotEmpty = !!Object.keys(meta.blockchains).length;
if (blockchainsMetaNotEmpty) {
explorerUrl = getScannerUrl(
currentStep.executedTransactionId,
currentStepBlockchain,
currentStepNamespace.network,
meta.blockchains
);
}
Expand Down
8 changes: 5 additions & 3 deletions queue-manager/rango-preset/src/actions/executeTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
signTransaction,
updateNetworkStatus,
} from '../helpers';
import { getCurrentBlockchainOf } from '../shared';
import { getCurrentNamespaceOf } from '../shared';
import { BlockReason } from '../types';

/**
Expand Down Expand Up @@ -95,8 +95,10 @@ export async function executeTransaction(
requestBlock(blockedFor);
return;
} else if (!networkMatched) {
const fromBlockchain = getCurrentBlockchainOf(swap, currentStep);
const details = ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(fromBlockchain);
const fromNamespace = getCurrentNamespaceOf(swap, currentStep);
const details = ERROR_MESSAGE_WAIT_FOR_CHANGE_NETWORK(
fromNamespace.network
);

const blockedFor = {
reason: BlockReason.WAIT_FOR_NETWORK_CHANGE,
Expand Down
67 changes: 37 additions & 30 deletions queue-manager/rango-preset/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable destructuring/in-params */
/* eslint-disable @typescript-eslint/no-magic-numbers */
/* eslint-disable @typescript-eslint/no-floating-promises */
import type { SwapStatus, Wallet } from './shared';
import type { SwapStatus, TargetNamespace, Wallet } from './shared';
import type {
ArrayElement,
Step,
Expand Down Expand Up @@ -57,8 +57,8 @@ import { httpService } from './services';
import { notifier } from './services/eventEmitter';
import {
getCurrentAddressOf,
getCurrentBlockchainOf,
getCurrentBlockchainOfOrNull,
getCurrentNamespaceOf,
getCurrentNamespaceOfOrNull,
getRelatedWallet,
getRelatedWalletOrNull,
getScannerUrl,
Expand Down Expand Up @@ -519,9 +519,9 @@ export function markRunningSwapAsSwitchingNetwork({

// Generate message
const { type } = getRequiredWallet(swap);
const fromBlockchain = getCurrentBlockchainOf(swap, currentStep);
const reason = `Change ${type} wallet network to ${fromBlockchain}`;
const reasonDetail = `Please change your ${type} wallet network to ${fromBlockchain}.`;
const fromNamespace = getCurrentNamespaceOf(swap, currentStep);
const reason = `Change ${type} wallet network to ${fromNamespace.network}`;
const reasonDetail = `Please change your ${type} wallet network to ${fromNamespace.namespace}.`;

const currentTime = new Date();
swap.lastNotificationTime = currentTime.getTime().toString();
Expand Down Expand Up @@ -621,26 +621,26 @@ export function isWalletNull(wallet: Wallet | null): boolean {
*/
export function getRequiredWallet(swap: PendingSwap): {
type: WalletType | null;
network: Network | null;
namespace: TargetNamespace | null;
address: string | null;
} {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const step = getCurrentStep(swap)!;
const bcName = getCurrentBlockchainOfOrNull(swap, step);
if (!bcName) {
const currentNamespace = getCurrentNamespaceOfOrNull(swap, step);
if (!currentNamespace) {
return {
type: null,
network: null,
namespace: null,
address: null,
};
}

const walletType = getSwapWalletType(swap, bcName);
const sourceWallet = swap.wallets[bcName];
const walletType = getSwapWalletType(swap, currentNamespace.network);
const sourceWallet = swap.wallets[currentNamespace.network];

return {
type: walletType || null,
network: bcName,
namespace: currentNamespace,
address: sourceWallet ? sourceWallet.address : null,
};
}
Expand Down Expand Up @@ -674,18 +674,18 @@ export async function isNetworkMatchedForTransaction(
if (isWalletNull(wallet)) {
return false;
}
const fromBlockChain = getCurrentBlockchainOfOrNull(swap, step);
if (!fromBlockChain) {
const fromNamespace = getCurrentNamespaceOfOrNull(swap, step);
if (!fromNamespace) {
return false;
}

if (
meta.evmBasedChains.find(
(evmBlochain) => evmBlochain.name === fromBlockChain
(evmBlochain) => evmBlochain.name === fromNamespace.network
)
) {
try {
const sourceWallet = swap.wallets[fromBlockChain];
const sourceWallet = swap.wallets[fromNamespace.network];
if (sourceWallet) {
const provider = getEvmProvider(providers, sourceWallet.walletType);
const chainId: number | string | null = await getChainId(provider);
Expand All @@ -698,13 +698,13 @@ export async function isNetworkMatchedForTransaction(
);
if (
blockChain &&
blockChain.toLowerCase() === fromBlockChain.toLowerCase()
blockChain.toLowerCase() === fromNamespace.network.toLowerCase()
) {
return true;
}
if (
blockChain &&
blockChain.toLowerCase() !== fromBlockChain.toLowerCase()
blockChain.toLowerCase() !== fromNamespace.network.toLowerCase()
) {
return false;
}
Expand Down Expand Up @@ -856,7 +856,10 @@ export function onBlockForChangeNetwork(
setStorage: queue.setStorage.bind(queue),
});

const requiredNetwork = getCurrentBlockchainOfOrNull(swap, currentStep);
const requiredNetwork = getCurrentNamespaceOfOrNull(
swap,
currentStep
)?.network;

const requiredWallet = getRequiredWallet(swap).type;

Expand All @@ -878,10 +881,10 @@ export function onBlockForChangeNetwork(
}

// Try to auto switch
const { type, network } = getRequiredWallet(swap);
if (!!type && !!network) {
if (context.canSwitchNetworkTo(type, network)) {
const result = context.switchNetwork(type, network);
const { type, namespace } = getRequiredWallet(swap);
if (!!type && !!namespace?.network) {
if (context.canSwitchNetworkTo(type, namespace.network)) {
const result = context.switchNetwork(type, namespace);
if (result) {
result
.then(() => {
Expand Down Expand Up @@ -950,7 +953,7 @@ export function onDependsOnOtherQueues(

setClaimer(task.queue_id);
const claimedStorage = task.storage.get() as SwapStorage;
const { type, network, address } = getRequiredWallet(
const { type, namespace, address } = getRequiredWallet(
claimedStorage.swapDetails
);

Expand All @@ -961,7 +964,7 @@ export function onDependsOnOtherQueues(
reset();
// TODO: Use key generator
retryOn(
`${type}-${network}:${address}`,
`${type}-${namespace?.network}:${address}`,
manager,
context.canSwitchNetworkTo
);
Expand Down Expand Up @@ -1004,7 +1007,7 @@ export async function signTransaction(
const sourceWallet = getRelatedWallet(swap, currentStep);
const mobileWallet = isMobileWallet(sourceWallet?.walletType);
const walletAddress = getCurrentAddressOf(swap, currentStep);
const currentStepBlockchain = getCurrentBlockchainOf(swap, currentStep);
const currentStepNamespace = getCurrentNamespaceOf(swap, currentStep);

const onFinish = () => {
// TODO resetClaimedBy is undefined here
Expand Down Expand Up @@ -1116,7 +1119,7 @@ export async function signTransaction(
({ hash, response }) => {
const explorerUrl = getScannerUrl(
hash,
currentStepBlockchain,
currentStepNamespace.network,
meta.blockchains
);
setStepTransactionIds(
Expand Down Expand Up @@ -1215,7 +1218,10 @@ export function checkWaitingForConnectWalletChange(params: {
}
);

const requiredNetwork = getCurrentBlockchainOfOrNull(swap, currentStep);
const requiredNetwork = getCurrentNamespaceOfOrNull(
swap,
currentStep
)?.network;

if (
currentStepRequiredWallet === wallet &&
Expand Down Expand Up @@ -1386,7 +1392,8 @@ export function retryOn(
const currentStep = getCurrentStep(swap);
if (currentStep) {
if (
getCurrentBlockchainOfOrNull(swap, currentStep) == network &&
getCurrentNamespaceOfOrNull(swap, currentStep)?.network ==
network &&
queueStorage?.swapDetails.wallets[network]?.walletType === wallet
) {
walletAndNetworkMatched.push(q.list);
Expand Down
8 changes: 6 additions & 2 deletions queue-manager/rango-preset/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ export {
StepExecutionBlockedEventStatus,
EventSeverity,
} from './types';
export type { PendingSwapWithQueueID, EventType } from './shared';
export type {
PendingSwapWithQueueID,
EventType,
TargetNamespace,
} from './shared';
export {
getCurrentBlockchainOfOrNull,
getCurrentNamespaceOfOrNull,
getRelatedWalletOrNull,
getRelatedWallet,
MessageSeverity,
Expand Down
8 changes: 4 additions & 4 deletions queue-manager/rango-preset/src/services/eventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
getLastSuccessfulStep,
isApprovalCurrentStepTx,
} from '../helpers';
import { getCurrentBlockchainOfOrNull } from '../shared';
import { getCurrentNamespaceOfOrNull } from '../shared';
import {
EventSeverity,
RouteEventType,
Expand Down Expand Up @@ -178,8 +178,8 @@ export function notifier(params: NotifierParams) {
const fromAsset = `${step.fromBlockchain}.${step.fromSymbol}`;
const toAsset = `${step.toBlockchain}.${step.toSymbol}`;
const outputAmount = step.outputAmount ?? '';
const currentFromBlockchain = !!params.step
? getCurrentBlockchainOfOrNull(params.swap, params.step)
const currentFromNamespace = !!params.step
? getCurrentNamespaceOfOrNull(params.swap, params.step)
: null;
let message = '';
let messageSeverity: StepEvent['messageSeverity'] = EventSeverity.INFO;
Expand Down Expand Up @@ -254,7 +254,7 @@ export function notifier(params: NotifierParams) {
event.status ===
StepExecutionBlockedEventStatus.WAITING_FOR_NETWORK_CHANGE
) {
message = `Please change your wallet network to ${currentFromBlockchain}.`;
message = `Please change your wallet network to ${currentFromNamespace?.network}.`;
messageSeverity = EventSeverity.WARNING;
}
break;
Expand Down
Loading
Loading