@@ -25,21 +25,21 @@ interface ToasterMessage {
25
25
timeout ?: string ;
26
26
}
27
27
28
- interface DnsAllocParams {
28
+ export interface DnsAllocParams {
29
29
domain : string ;
30
30
targetAddress : string ;
31
31
coins ?: bigint ;
32
32
}
33
33
34
- interface DnsDeleteParams {
34
+ export interface DnsDeleteParams {
35
35
tokenId : bigint ;
36
36
}
37
37
38
38
interface DnsUserEntryListParams {
39
39
address : string ;
40
40
}
41
41
42
- interface DnsChangeTargetParams {
42
+ export interface DnsChangeTargetParams {
43
43
domain : string ;
44
44
targetAddress : string ;
45
45
}
@@ -51,8 +51,8 @@ export interface DnsUserEntryListResult {
51
51
}
52
52
53
53
export interface DnsGetAllocCostResponse {
54
- price : bigint | null ;
55
- error ?: string ;
54
+ price : bigint | null ;
55
+ error ?: string ;
56
56
}
57
57
58
58
type callSmartContractOptions = {
@@ -72,8 +72,10 @@ export function useWriteMNS(client?: Client) {
72
72
const [ list , setList ] = useState < DnsUserEntryListResult [ ] > ( [ ] ) ;
73
73
const [ listSpinning , setListSpinning ] = useState ( false ) ;
74
74
75
- async function getAllocCost ( params : DnsAllocParams ) : Promise < DnsGetAllocCostResponse > {
76
- let price = 0n
75
+ async function getAllocCost (
76
+ params : DnsAllocParams ,
77
+ ) : Promise < DnsGetAllocCostResponse > {
78
+ let price = 0n ;
77
79
try {
78
80
let args = new Args ( ) ;
79
81
args . addString ( params . domain ) ;
@@ -85,62 +87,73 @@ export function useWriteMNS(client?: Client) {
85
87
} ) ;
86
88
if ( ! response ) {
87
89
return {
88
- price : null ,
89
- error : 'Failed to get alloc cost' ,
90
+ price : null ,
91
+ error : 'Failed to get alloc cost' ,
90
92
} ;
91
93
}
92
- price = bytesToU64 ( response . returnValue ) ;
94
+ price = bytesToU64 ( response . returnValue ) ;
93
95
} catch ( error ) {
94
96
return {
95
- price : null ,
96
- error : 'Invalid domain name. Name can only be 2-100 characters long and can contains only lowercase letters, numbers and hyphens.' ,
97
+ price : null ,
98
+ error :
99
+ 'Name can only be 2-100 characters long and can contains only lowercase letters, numbers and hyphens.' ,
97
100
} ;
98
101
}
99
102
try {
100
- let args = new Args ( ) ;
101
- args . addString ( params . domain ) ;
102
- let result = await client ?. smartContracts ( ) . readSmartContract ( {
103
- targetAddress : SC_ADDRESS ,
104
- targetFunction : 'dnsResolve' ,
105
- parameter : args . serialize ( ) ,
106
- } ) ;
107
- if ( ! result ) {
108
- return {
109
- price : null ,
110
- error : 'Failed to get alloc cost' ,
111
- } ;
112
- }
103
+ let args = new Args ( ) ;
104
+ args . addString ( params . domain ) ;
105
+ let result = await client ?. smartContracts ( ) . readSmartContract ( {
106
+ targetAddress : SC_ADDRESS ,
107
+ targetFunction : 'dnsResolve' ,
108
+ parameter : args . serialize ( ) ,
109
+ } ) ;
110
+ if ( ! result ) {
113
111
return {
114
- price : null ,
115
- error : `Domain already claimed by ${ bytesToStr ( result . returnValue ) } ` ,
116
- }
112
+ price : null ,
113
+ error : 'Failed to get alloc cost' ,
114
+ } ;
115
+ }
116
+ return {
117
+ price : null ,
118
+ error : `Domain already claimed by ${ bytesToStr ( result . returnValue ) } ` ,
119
+ } ;
117
120
} catch ( error ) {
118
- }
119
- try {
120
- let resultBalance = await client ?. publicApi ( ) . getAddresses ( [ params . targetAddress ] ) ;
121
- if ( ! resultBalance ) {
122
- return {
121
+ try {
122
+ let resultBalance = await client
123
+ ?. publicApi ( )
124
+ . getAddresses ( [ params . targetAddress ] ) ;
125
+ if ( ! resultBalance ) {
126
+ return {
123
127
price : null ,
124
128
error : 'Failed to get alloc cost' ,
125
- } ;
126
- }
127
- let balance = BigInt ( ( parseFloat ( resultBalance [ 0 ] . candidate_balance ) * 1_000_000_000 ) . toFixed ( 0 ) ) ;
128
- if ( balance < price ) {
129
- return {
129
+ } ;
130
+ }
131
+ let balance = BigInt (
132
+ (
133
+ parseFloat ( resultBalance [ 0 ] . candidate_balance ) * 1_000_000_000
134
+ ) . toFixed ( 0 ) ,
135
+ ) ;
136
+ if ( balance < price ) {
137
+ return {
130
138
price : null ,
131
- error : `The price of the domain is ${ toMAS ( price ) . toFixed ( 4 ) } MAS. Your balance is ${ toMAS ( balance ) . toFixed ( 4 ) } MAS. Please top up your account.`
139
+ error : `The price of the domain is ${ toMAS ( price ) . toFixed (
140
+ 4 ,
141
+ ) } MAS. Your balance is ${ toMAS ( balance ) . toFixed (
142
+ 4 ,
143
+ ) } MAS. Please top up your account.`,
144
+ } ;
132
145
}
133
- }
134
- } catch ( error ) {
135
- console . log ( error )
146
+ } catch ( error ) {
136
147
return {
137
- price : null ,
138
- error : 'Your account does not exist in the Massa network. Please transfer 0.1 MAS to your account to create it on chain.' ,
148
+ price : null ,
149
+ error :
150
+ 'Your account does not exist in the Massa network. Transfer 0.1 MAS to your account to create it onchain.' ,
139
151
} ;
140
- }
141
- return {
152
+ }
153
+ return {
142
154
price : price ,
143
- } ;
155
+ } ;
156
+ }
144
157
}
145
158
146
159
function callSmartContract (
@@ -218,7 +231,12 @@ export function useWriteMNS(client?: Client) {
218
231
setIsSuccess ( true ) ;
219
232
setIsPending ( false ) ;
220
233
toast . dismiss ( toastId ) ;
221
- getUserEntryList ( { address : client . wallet ( ) . getBaseAccount ( ) ?. address ( ) ! } )
234
+ const baseAccount = client . wallet ( ) . getBaseAccount ( ) ;
235
+ if ( client && baseAccount ) {
236
+ getUserEntryList ( {
237
+ address : baseAccount . address ( ) ! ,
238
+ } ) ;
239
+ }
222
240
toast . success ( ( t ) => (
223
241
< ToastContent t = { t } >
224
242
< OperationToast
@@ -326,7 +344,6 @@ export function useWriteMNS(client?: Client) {
326
344
if ( ! entry || entry . length == 0 ) {
327
345
continue ;
328
346
}
329
- console . log ( entry , addressBytes ) ;
330
347
if ( compareUint8Array ( entry , addressBytes ) ) {
331
348
let tokenId = i + BigInt ( j ) ;
332
349
let resultDomain = await client ?. smartContracts ( ) . readSmartContract ( {
@@ -367,7 +384,6 @@ export function useWriteMNS(client?: Client) {
367
384
setListSpinning ( false ) ;
368
385
return list ;
369
386
}
370
- console . log ( 'listSpinning in hook' , listSpinning ) ;
371
387
372
388
const sleep = ( ms : number ) => new Promise ( ( r ) => setTimeout ( r , ms ) ) ;
373
389
0 commit comments