Skip to content

Commit

Permalink
chore: send flow type to enum (#532)
Browse files Browse the repository at this point in the history
* Adjust network recipient selection

* Integrate token unwrapping

* Polish code for review

* Fix type checker

* Cleanup code

* Fix imports

* Add gas fee support for native token unwrapping

* Only allow unwrapping for appropriate token types

* Cleanup code

* chore: move SendFlowType into separate file

* chore: consistent casing

* chore: cleanup logic

* fix: update imports

* fix: import

---------

Co-authored-by: Matthew Maxwell <[email protected]>
Co-authored-by: Mark Nardi <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2023
1 parent bbed412 commit 3e12b36
Show file tree
Hide file tree
Showing 20 changed files with 38 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
const sendFlowType = token.id === BASE_TOKEN_ID ? SendFlowType.BaseCoinTransfer : SendFlowType.TokenTransfer
setSendFlowParameters({
type: sendFlowType,
[sendFlowType === SendFlowType.BaseCoinTransfer ? 'baseCoinTransfer' : 'tokenTransfer']: {
token: token,
[sendFlowType]: {
token,
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import { getBaseToken } from '@core/profile/actions'
import { collectiblesRouter } from '@core/router/routers'
import { formatTokenAmountPrecise } from '@core/token'
import { getBech32AddressFromAddressTypes, getHexAddressFromAddressTypes } from '@core/wallet'
import { getBech32AddressFromAddressTypes, getHexAddressFromAddressTypes, SendFlowType } from '@core/wallet'
import { getTimeDifference } from '@core/utils'
import { SendFlowType, setSendFlowParameters } from '@core/wallet/stores'
import { setSendFlowParameters } from '@core/wallet/stores'
import { PopupId, openPopup } from '@desktop/auxiliary/popup'
import { Button, Modal, NftMedia, Pane, Text } from '@ui'
import { FontWeight, TextType } from '@ui/enums'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@
let rawAmount: string
let amount: string
let unit: string
const tokenKey = $sendFlowParameters.type === SendFlowType.TokenTransfer ? 'tokenTransfer' : 'baseCoinTransfer'
if (
$sendFlowParameters.type === SendFlowType.BaseCoinTransfer ||
$sendFlowParameters.type === SendFlowType.TokenTransfer
) {
const sendFlowType = $sendFlowParameters.type
if (sendFlowType === SendFlowType.BaseCoinTransfer || sendFlowType === SendFlowType.TokenTransfer) {
token = getTokenFromSelectedAccountTokens(
$sendFlowParameters[tokenKey].token?.id,
$sendFlowParameters[tokenKey].token?.networkId
$sendFlowParameters[sendFlowType].token?.id,
$sendFlowParameters[sendFlowType].token?.networkId
)
rawAmount = $sendFlowParameters[tokenKey].rawAmount
unit = $sendFlowParameters[tokenKey].unit || getUnitFromTokenMetadata(token?.metadata)
rawAmount = $sendFlowParameters[sendFlowType].rawAmount
unit = $sendFlowParameters[sendFlowType].unit || getUnitFromTokenMetadata(token?.metadata)
}
$: tokenBalance = getTokenBalance(token?.id, token?.networkId)
Expand All @@ -43,8 +40,8 @@
updateSendFlowParameters({
type: $sendFlowParameters.type,
[tokenKey]: {
token: $sendFlowParameters[tokenKey].token,
[sendFlowType]: {
token,
rawAmount,
unit,
},
Expand All @@ -58,8 +55,8 @@
function onBackClick(): void {
updateSendFlowParameters({
type: $sendFlowParameters.type,
[tokenKey]: {
token: $sendFlowParameters[tokenKey].token,
[sendFlowType]: {
token,
rawAmount: undefined,
unit,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
setSendFlowParameters({
...previousSharedParameters,
type: sendFlowType,
[sendFlowType === SendFlowType.BaseCoinTransfer ? 'baseCoinTransfer' : 'tokenTransfer']: {
[sendFlowType]: {
token: selectedToken,
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
calculateMaxGasFeeFromTransactionData,
} from '@core/layer-2'
import { INft } from '@core/nfts'
import { SendFlowParameters, TokenTransferData } from '@core/wallet'
import { SendFlowType } from '@core/wallet/stores'
import { SendFlowParameters, SendFlowType, TokenTransferData } from '@core/wallet'
import { TransactionAssetSection } from '@ui'
import EvmTransactionDetails from './EvmTransactionDetails.svelte'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import { INft } from '@core/nfts/interfaces'
import { selectedAccountTokens } from '@core/token/stores'
import { TimePeriod } from '@core/utils/enums'
import { Output, SendFlowParameters, TokenTransferData } from '@core/wallet'
import { SendFlowType, updateSendFlowParameters } from '@core/wallet/stores'
import { Output, SendFlowParameters, SendFlowType, TokenTransferData } from '@core/wallet'
import { updateSendFlowParameters } from '@core/wallet/stores'
import { AddInputButton, OptionalInput, TransactionAssetSection } from '@ui'
import { onMount } from 'svelte'
import StardustTransactionDetails from './StardustTransactionDetails.svelte'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NetworkId } from '@core/network/types'
import { isEvmChain } from '@core/network/utils'
import { SendFlowType } from '@core/wallet/stores'
import { SendFlowType } from '@core/wallet/enums'

import { getEvmChainGasPrice, getLayer2AccountBalanceForToken } from '../stores'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SendFlowType } from '@core/wallet/stores'
import { SendFlowType } from '@core/wallet/enums'

/**
* We need a fallback estimated gas, since we cannot estimate calls to the magic contract if there is no balance on the sender address.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { formatTokenAmountDefault } from '@core/token'
import { SendFlowType, sendFlowParameters } from '@core/wallet/stores'
import { sendFlowParameters } from '@core/wallet/stores'
import { SendFlowType } from '@core/wallet/enums'
import { get } from 'svelte/store'
import { PopupProps } from '../../../../../../desktop/lib/auxiliary/popup/types'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getErc20TransferSmartContractData } from '@core/layer-2/utils'
import { TokenStandard } from '@core/token/enums'
import { IToken } from '@core/token/interfaces'

import { SendFlowType } from '../../stores'
import { SendFlowType } from '../../enums'
import { SendFlowParameters } from '../../types'

export function createEvmChainToEvmChainTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { buildAssetAllowance } from '@core/layer-2/utils'
import { ETHEREUM_COIN_TYPE } from '@core/network/constants'
import { IChain } from '@core/network/interfaces'

import { SendFlowType } from '../../stores'
import { SendFlowType } from '../../enums'
import { SendFlowParameters } from '../../types'
import { buildTransferredAssetFromSendFlowParameters } from '../../utils'

Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/lib/core/wallet/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './irc27-version.enum'
export * from './return-strategy.enum'
export * from './send-flow-type.enum'
export * from './subject-type.enum'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum SendFlowType {
BaseCoinTransfer = 'baseCoinTransfer',
TokenTransfer = 'tokenTransfer',
TokenUnwrap = 'tokenUnwrap',
NftTransfer = 'nftTransfer',
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { writable, Writable } from 'svelte/store'
import { SendFlowType } from '../enums'
import type { SendFlowParameters } from '../types'

// TODO: Move enum
export enum SendFlowType {
BaseCoinTransfer = 'BaseCoinTransfer',
TokenTransfer = 'TokenTransfer',
TokenUnwrap = 'tokenUnwrap',
NftTransfer = 'NftTransfer',
}

export const sendFlowParameters: Writable<SendFlowParameters | undefined> = writable(undefined)

export function setSendFlowParameters(payload: SendFlowParameters): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getOutputParameters } from '../utils'
import { ReturnStrategy, SubjectType } from '../enums'
import { IToken, IPersistedToken } from '@core/token/interfaces'
import { TokenStandard, VerifiedStatus } from '@core/token/enums'
import { SendFlowType } from '../stores'
import { SendFlowType } from '../enums'
import { SendFlowParameters } from '../types'

const PERSISTED_ASSET_SHIMMER: IPersistedToken = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NetworkId } from '@core/network'
import { INft } from '@core/nfts'
import { IToken } from '@core/token/interfaces'
import type { Subject } from '@core/wallet'
import { SendFlowType } from '@core/wallet/stores'
import { SendFlowType } from '@core/wallet/enums'

export type SendFlowParameters = TokenSendFlowParameters | NftSendFlowParameters | BaseSendFlowParameters

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NetworkId } from '@core/network/types'
import { SendFlowType } from '../stores'
import { SendFlowType } from '../enums'
import { SendFlowParameters } from '../types'

export function getNetworkIdFromSendFlowParameters(params: SendFlowParameters): NetworkId | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BASE_TOKEN_ID } from '@core/token'
import { Converter, convertDateToUnixTimestamp } from '@core/utils'
import { SendFlowParameters, Subject } from '@core/wallet/types'
import { ReturnStrategy } from '../enums'
import { SendFlowType } from '../stores'
import { SendFlowType } from '../enums'

export async function getOutputParameters(
sendFlowParameters: SendFlowParameters,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SendFlowType } from '../stores'
import { SendFlowType } from '../enums'
import { SendFlowParameters } from '../types'

export function getTokenIdFromSendFlowParameters(params: SendFlowParameters): string | undefined {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SendFlowType } from '../stores'
import { SendFlowType } from '../enums'
import { SendFlowParameters } from '../types'

export function getTokenStandardFromSendFlowParameters(params: SendFlowParameters): string | undefined {
Expand Down

0 comments on commit 3e12b36

Please sign in to comment.