-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add links to bridge transfer modal (#1362)
* add links to modal, update BridgeTransactionMixin * fix sub tx recipientAmount in reducer * account links in BridgeTransactionView * refactoring transaction view links * add node connection allowance timeout * return app align center * remove rococo block explorer url * fix ts issue * refactoring sonar issues * remove isOutgoingType from mixin * remove unused code
- Loading branch information
1 parent
742a1cf
commit 4713ea3
Showing
18 changed files
with
433 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,108 @@ | ||
import { BridgeTxStatus } from '@sora-substrate/util/build/bridgeProxy/consts'; | ||
import { BridgeNetworkType } from '@sora-substrate/util/build/bridgeProxy/consts'; | ||
import { WALLET_CONSTS } from '@soramitsu/soraneo-wallet-web'; | ||
import { Component, Mixins } from 'vue-property-decorator'; | ||
|
||
import TranslationMixin from '@/components/mixins/TranslationMixin'; | ||
import { isOutgoingTransaction } from '@/utils/bridge/common/utils'; | ||
import { isUnsignedToPart } from '@/utils/bridge/eth/utils'; | ||
import NetworkFormatterMixin from '@/components/mixins/NetworkFormatterMixin'; | ||
import { soraExplorerLinks } from '@/utils'; | ||
|
||
import type { IBridgeTransaction } from '@sora-substrate/util'; | ||
|
||
const { ETH_BRIDGE_STATES } = WALLET_CONSTS; | ||
import type { BridgeNetworkId } from '@sora-substrate/util/build/bridgeProxy/types'; | ||
|
||
@Component | ||
export default class BridgeTransactionMixin extends Mixins(TranslationMixin) { | ||
isFailedState(item: Nullable<IBridgeTransaction>): boolean { | ||
if (!(item && item.transactionState)) return false; | ||
// ETH | ||
if ( | ||
[ETH_BRIDGE_STATES.EVM_REJECTED as string, ETH_BRIDGE_STATES.SORA_REJECTED as string].includes( | ||
item.transactionState | ||
) | ||
) | ||
return true; | ||
// EVM | ||
if (item.transactionState === BridgeTxStatus.Failed) return true; | ||
// OTHER | ||
return false; | ||
} | ||
|
||
isSuccessState(item: Nullable<IBridgeTransaction>): boolean { | ||
if (!item) return false; | ||
// ETH | ||
if ( | ||
item.transactionState === | ||
(isOutgoingTransaction(item) ? ETH_BRIDGE_STATES.EVM_COMMITED : ETH_BRIDGE_STATES.SORA_COMMITED) | ||
) | ||
return true; | ||
// EVM | ||
if (item.transactionState === BridgeTxStatus.Done) return true; | ||
// OTHER | ||
return false; | ||
} | ||
|
||
isWaitingForAction(item: Nullable<IBridgeTransaction>): boolean { | ||
if (!item) return false; | ||
// ETH | ||
return item.transactionState === ETH_BRIDGE_STATES.EVM_REJECTED && isUnsignedToPart(item); | ||
} | ||
|
||
formatDatetime(item: Nullable<IBridgeTransaction>): string { | ||
return this.formatDate(item?.startTime ?? Date.now()); | ||
export default class BridgeTransactionMixin extends Mixins(NetworkFormatterMixin) { | ||
get tx(): Nullable<IBridgeTransaction> { | ||
console.warn('[BridgeTransactionMixin] "tx" computed property is not implemented'); | ||
return null; | ||
} | ||
|
||
get isOutgoing(): boolean { | ||
return this.isOutgoingTx(this.tx); | ||
} | ||
|
||
get isEvmTxType(): boolean { | ||
return ( | ||
!!this.externalNetworkType && [BridgeNetworkType.Eth, BridgeNetworkType.Evm].includes(this.externalNetworkType) | ||
); | ||
} | ||
|
||
get txSoraAccount(): string { | ||
return this.tx?.from ?? ''; | ||
} | ||
|
||
get txExternalAccount(): string { | ||
return this.tx?.to ?? ''; | ||
} | ||
|
||
get txSoraId(): string { | ||
return this.tx?.txId ?? ''; | ||
} | ||
|
||
get txSoraBlockId(): string { | ||
return this.tx?.blockId ?? ''; | ||
} | ||
|
||
get txSoraHash(): string { | ||
return this.tx?.hash ?? ''; | ||
} | ||
|
||
get txInternalHash(): string { | ||
if (!this.isOutgoing) return this.txSoraHash; | ||
|
||
return this.txSoraHash || this.txSoraBlockId || this.txSoraId; | ||
} | ||
|
||
get txExternalHash(): string { | ||
return this.tx?.externalHash ?? this.txExternalBlockId; | ||
} | ||
|
||
get txExternalBlockId(): string { | ||
return this.tx?.externalBlockId ?? ''; | ||
} | ||
|
||
get externalNetworkType(): Nullable<BridgeNetworkType> { | ||
return this.tx?.externalNetworkType; | ||
} | ||
|
||
get externalNetworkId(): Nullable<BridgeNetworkId> { | ||
return this.tx?.externalNetwork; | ||
} | ||
|
||
get soraExplorerLinks(): Array<WALLET_CONSTS.ExplorerLink> { | ||
return soraExplorerLinks(this.soraNetwork, this.txSoraId, this.txSoraBlockId); | ||
} | ||
|
||
get externalExplorerLinks(): Array<WALLET_CONSTS.ExplorerLink> { | ||
if (!(this.externalNetworkType && this.externalNetworkId)) return []; | ||
|
||
return this.getNetworkExplorerLinks( | ||
this.externalNetworkType, | ||
this.externalNetworkId, | ||
this.txExternalHash, | ||
this.txExternalBlockId, | ||
this.EvmLinkType.Transaction | ||
); | ||
} | ||
|
||
get internalAccountLinks(): Array<WALLET_CONSTS.ExplorerLink> { | ||
return soraExplorerLinks(this.soraNetwork, this.txSoraAccount, this.txSoraBlockId, true); | ||
} | ||
|
||
get externalAccountLinks(): Array<WALLET_CONSTS.ExplorerLink> { | ||
if (!(this.externalNetworkType && this.externalNetworkId)) return []; | ||
|
||
return this.getNetworkExplorerLinks( | ||
this.externalNetworkType, | ||
this.externalNetworkId, | ||
this.txExternalAccount, | ||
this.txExternalBlockId, | ||
this.EvmLinkType.Account | ||
); | ||
} | ||
|
||
getNetworkText(text: string, networkId?: Nullable<BridgeNetworkId>, approximate = false): string { | ||
const network = networkId ? this.getNetworkName(this.externalNetworkType, networkId) : this.TranslationConsts.Sora; | ||
const approx = approximate ? this.TranslationConsts.Max : ''; | ||
|
||
return [approx, network, text].filter((item) => !!item).join(' '); | ||
} | ||
} |
Oops, something went wrong.