-
-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-native): better txn names according to desktop logic
- Loading branch information
Showing
5 changed files
with
109 additions
and
43 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
64 changes: 64 additions & 0 deletions
64
suite-native/transactions/src/components/TransactionName.tsx
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { WalletAccountTransaction } from '@suite-common/wallet-types'; | ||
import { Translation, TxKeyPath } from '@suite-native/intl'; | ||
|
||
type TransactionNameProps = { | ||
transaction: WalletAccountTransaction; | ||
isPending: boolean; | ||
}; | ||
|
||
interface GetSelfTransactionMessageByTypeProps { | ||
type?: Required<WalletAccountTransaction>['cardanoSpecific']['subtype']; | ||
} | ||
|
||
const getSelfTransactionMessageByType = ({ | ||
type, | ||
}: GetSelfTransactionMessageByTypeProps): TxKeyPath => { | ||
switch (type) { | ||
case 'withdrawal': | ||
return 'transactions.name.withdrawal'; | ||
case 'stake_delegation': | ||
return 'transactions.name.stake_delegation'; | ||
case 'stake_registration': | ||
return 'transactions.name.stake_registration'; | ||
case 'stake_deregistration': | ||
return 'transactions.name.stake_deregistration'; | ||
default: | ||
return 'transactions.name.self'; | ||
} | ||
}; | ||
|
||
export const getTransactionName = ( | ||
transaction: WalletAccountTransaction, | ||
isPending: boolean, | ||
): TxKeyPath => { | ||
switch (transaction.type) { | ||
case 'sent': | ||
return isPending ? 'transactions.name.sending' : 'transactions.name.sent'; | ||
case 'recv': | ||
return isPending ? 'transactions.name.receiving' : 'transactions.name.received'; | ||
case 'failed': | ||
return 'transactions.name.failed'; | ||
case 'joint': | ||
return 'transactions.name.joint'; | ||
case 'contract': | ||
return 'transactions.name.contract'; | ||
case 'self': | ||
return getSelfTransactionMessageByType({ | ||
type: transaction.cardanoSpecific?.subtype, | ||
}); | ||
case 'unknown': | ||
default: | ||
return isPending ? 'transactions.name.pending' : 'transactions.name.unknown'; | ||
} | ||
}; | ||
|
||
export const TransactionName = ({ transaction, isPending }: TransactionNameProps) => { | ||
const ethName = transaction.ethereumSpecific?.parsedData?.name; | ||
|
||
// use name of eth txns, but for Transfer | ||
if (ethName && !(ethName === 'Transfer' && ['recv', 'sent'].includes(transaction.type))) { | ||
return ethName; | ||
} | ||
|
||
return <Translation id={getTransactionName(transaction, isPending)} />; | ||
}; |
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