@@ -24,72 +24,13 @@ import {
24
24
import SendConfirmed from "../../svgs/SendConfirmed" ;
25
25
import Rubics from "../../svgs/Rubics" ;
26
26
import { useRouter , Stack } from "expo-router" ;
27
-
28
- const isValidBigInt = ( num : string ) => {
29
- if ( num . length === 0 ) return false ;
30
- try {
31
- const bi = BigInt ( num ) ;
32
- return bi > 0 ;
33
- } catch {
34
- return false ;
35
- }
36
- } ;
37
-
38
- const convertAmountToMinor = (
39
- amount : string ,
40
- assetId : string ,
41
- assetMap : Map < string , Asset > ,
42
- ) : [ bigint , null ] | [ null , Error ] => {
43
- const asset =
44
- assetId === IRON_ASSET_ID_HEX ? undefined : assetMap . get ( assetId ) ;
45
- return CurrencyUtils . tryMajorToMinor ( amount , assetId , {
46
- decimals : getAssetDecimals ( asset ) ,
47
- } ) ;
48
- } ;
49
-
50
- const isValidAmount = (
51
- value : string ,
52
- assetId : string ,
53
- assetMap : Map < string , Asset > ,
54
- ) => {
55
- if ( value . length === 0 ) return true ;
56
-
57
- const asset =
58
- assetId === IRON_ASSET_ID_HEX ? undefined : assetMap . get ( assetId ) ;
59
-
60
- // For unverified assets, don't allow any decimals
61
- if ( asset && asset . verification . status !== "verified" ) {
62
- return ! value . includes ( "." ) ;
63
- }
64
-
65
- const decimals = getAssetDecimals ( asset ) ?? 8 ; // $IRON has 8 decimals by default
66
- const parts = value . split ( "." ) ;
67
- return parts . length <= 2 && ( parts [ 1 ] ?. length ?? 0 ) <= decimals ;
68
- } ;
69
-
70
- const enforceDecimals = (
71
- value : string ,
72
- assetId : string ,
73
- assetMap : Map < string , Asset > ,
74
- ) : string => {
75
- if ( value . length === 0 ) return value ;
76
-
77
- const asset =
78
- assetId === IRON_ASSET_ID_HEX ? undefined : assetMap . get ( assetId ) ;
79
-
80
- // For unverified assets, remove any decimal points
81
- if ( asset && asset . verification . status !== "verified" ) {
82
- return value . replace ( / \. / g, "" ) ;
83
- }
84
-
85
- const decimals = getAssetDecimals ( asset ) ?? 8 ;
86
- const parts = value . split ( "." ) ;
87
- if ( parts . length === 2 && parts [ 1 ] . length > decimals ) {
88
- return `${ parts [ 0 ] } .${ parts [ 1 ] . slice ( 0 , decimals ) } ` ;
89
- }
90
-
91
- return value ;
92
- } ;
27
+ import {
28
+ isValidBigInt ,
29
+ convertAmountToMinor ,
30
+ isValidAmount ,
31
+ enforceDecimals ,
32
+ getAssetDecimals ,
33
+ } from "../../utils/send.utils" ;
93
34
94
35
const CheckIcon = ( props : IconProps ) => (
95
36
< Icon { ...props } name = "checkmark-outline" />
@@ -98,18 +39,6 @@ const CheckIcon = (props: IconProps) => (
98
39
// First add a new type for the transaction state
99
40
type TransactionState = "sending" | "sent" | "idle" ;
100
41
101
- // Add this helper at the top with other utility functions
102
- const getAssetDecimals = ( asset : Asset | undefined ) : number | undefined => {
103
- if ( ! asset ) return undefined ;
104
- try {
105
- return asset . verification . status === "verified"
106
- ? asset . verification . decimals
107
- : JSON . parse ( asset . metadata ) . decimals ;
108
- } catch {
109
- return undefined ;
110
- }
111
- } ;
112
-
113
42
export default function Send ( ) {
114
43
const facade = useFacade ( ) ;
115
44
const router = useRouter ( ) ;
@@ -154,6 +83,9 @@ export default function Send() {
154
83
} ) ?? [ ] ,
155
84
} ) ;
156
85
86
+ // Add the mutation
87
+ const sendTransactionMutation = facade . sendTransaction . useMutation ( ) ;
88
+
157
89
const assetMap = useMemo ( ( ) => {
158
90
const map = new Map < string , Asset > ( ) ;
159
91
for ( const asset of getCustomAssets ) {
@@ -200,9 +132,6 @@ export default function Send() {
200
132
) ;
201
133
} , [ selectedAssetId , assetOptions ] ) ;
202
134
203
- // Add the mutation
204
- const sendTransactionMutation = facade . sendTransaction . useMutation ( ) ;
205
-
206
135
// Add amount validation
207
136
const amountError = useMemo ( ( ) => {
208
137
if ( ! amount ) return undefined ;
@@ -216,9 +145,6 @@ export default function Send() {
216
145
return `Maximum ${ decimals } decimal places allowed` ;
217
146
}
218
147
219
- const [ amountInMinorUnits ] =
220
- convertAmountToMinor ( amount , selectedAssetId , assetMap ) ?? [ ] ;
221
-
222
148
return undefined ;
223
149
} , [ amount , selectedAssetId , assetMap ] ) ;
224
150
0 commit comments