1+ import { printCommandHeader } from "../ui" ;
12import { Command } from "commander" ;
23import chalk from "chalk" ;
34import ora from "ora" ;
@@ -11,7 +12,8 @@ import {
1112} from "../../commands/delegate" ;
1213import { resolveTransferRecipient } from "../transfer" ;
1314import { addAuthOptions } from "./authOptions" ;
14- import { prepareContext } from "../context" ;
15+ import { prepareAssetHubContext , buildDotnsContext , buildReadOnlyDotnsContext } from "../context" ;
16+ import { makeOnStatus } from "../txStatus" ;
1517import { prepareReadOnlyContext } from "./lookup" ;
1618import {
1719 getMergedOptions ,
@@ -44,15 +46,14 @@ export function attachDelegateCommands(root: Command) {
4446 const jsonOutput = getJsonFlag ( command ) ;
4547 try {
4648 const mergedOptions = getMergedOptions ( command , options ) ;
47- const context = await maybeQuiet ( jsonOutput , ( ) =>
48- prepareContext ( { ...mergedOptions , useRevive : true } ) ,
49- ) ;
49+ const context = await maybeQuiet ( jsonOutput , ( ) => prepareAssetHubContext ( mergedOptions ) ) ;
5050
51- if ( ! jsonOutput ) console . log ( chalk . bold ( "\n▶ Delegate name\n" ) ) ;
51+ if ( ! jsonOutput ) printCommandHeader ( " Delegate name" ) ;
5252 const spinner = ora ( ) ;
53+ const ctx = buildDotnsContext ( context , { onStatus : makeOnStatus ( spinner , "Delegating" ) } ) ;
5354
5455 const delegateAddress = await maybeQuiet ( jsonOutput , ( ) =>
55- resolveTransferRecipient ( context . clientWrapper ! , context . substrateAddress , delegate ) ,
56+ resolveTransferRecipient ( ctx , delegate ) ,
5657 ) ;
5758
5859 if ( ! jsonOutput ) {
@@ -61,14 +62,7 @@ export function attachDelegateCommands(root: Command) {
6162 }
6263
6364 const result = await maybeQuiet ( jsonOutput , ( ) =>
64- setNameDelegate (
65- context . clientWrapper ! ,
66- context . substrateAddress ,
67- context . signer ,
68- name ,
69- delegateAddress as Address ,
70- spinner ,
71- ) ,
65+ setNameDelegate ( ctx , name , delegateAddress as Address ) ,
7266 ) ;
7367
7468 if ( ! emitJsonResult ( jsonOutput , result ) ) {
@@ -91,22 +85,15 @@ export function attachDelegateCommands(root: Command) {
9185 const jsonOutput = getJsonFlag ( command ) ;
9286 try {
9387 const mergedOptions = getMergedOptions ( command , options ) ;
94- const context = await maybeQuiet ( jsonOutput , ( ) =>
95- prepareContext ( { ...mergedOptions , useRevive : true } ) ,
96- ) ;
88+ const context = await maybeQuiet ( jsonOutput , ( ) => prepareAssetHubContext ( mergedOptions ) ) ;
9789
98- if ( ! jsonOutput ) console . log ( chalk . bold ( "\n▶ Revoke delegate\n" ) ) ;
90+ if ( ! jsonOutput ) printCommandHeader ( " Revoke delegate" ) ;
9991 const spinner = ora ( ) ;
92+ const ctx = buildDotnsContext ( context , {
93+ onStatus : makeOnStatus ( spinner , "Revoking delegate on" ) ,
94+ } ) ;
10095
101- const result = await maybeQuiet ( jsonOutput , ( ) =>
102- revokeNameDelegate (
103- context . clientWrapper ! ,
104- context . substrateAddress ,
105- context . signer ,
106- name ,
107- spinner ,
108- ) ,
109- ) ;
96+ const result = await maybeQuiet ( jsonOutput , ( ) => revokeNameDelegate ( ctx , name ) ) ;
11097
11198 if ( ! emitJsonResult ( jsonOutput , result ) ) {
11299 console . log ( chalk . gray ( " name: " ) + chalk . cyan ( result . name ) ) ;
@@ -133,12 +120,11 @@ export function attachDelegateCommands(root: Command) {
133120 prepareReadOnlyContext ( mergedOptions as never ) ,
134121 ) ;
135122
136- if ( ! jsonOutput ) console . log ( chalk . bold ( "\n▶ Delegate status\n" ) ) ;
123+ if ( ! jsonOutput ) printCommandHeader ( " Delegate status" ) ;
137124 const spinner = ora ( ) ;
125+ const ctx = buildReadOnlyDotnsContext ( context , { onStatus : makeOnStatus ( spinner ) } ) ;
138126
139- const delegate = await maybeQuiet ( jsonOutput , ( ) =>
140- getNameDelegate ( context . clientWrapper ! , context . account . address , name , spinner ) ,
141- ) ;
127+ const delegate = await maybeQuiet ( jsonOutput , ( ) => getNameDelegate ( ctx , name ) ) ;
142128
143129 if ( ! emitJsonResult ( jsonOutput , { name, delegate } ) ) {
144130 if ( delegate === null ) {
@@ -167,35 +153,27 @@ export function attachDelegateCommands(root: Command) {
167153 const jsonOutput = getJsonFlag ( command ) ;
168154 try {
169155 const mergedOptions = getMergedOptions ( command , options ) ;
170- const context = await maybeQuiet ( jsonOutput , ( ) =>
171- prepareContext ( { ...mergedOptions , useRevive : true } ) ,
172- ) ;
156+ const context = await maybeQuiet ( jsonOutput , ( ) => prepareAssetHubContext ( mergedOptions ) ) ;
173157
174158 const approved = ! options . revoke ;
175159 if ( ! jsonOutput ) {
176- console . log (
177- chalk . bold ( approved ? "\n▶ Delegate records\n" : "\n▶ Revoke record delegate\n" ) ,
178- ) ;
160+ printCommandHeader ( approved ? "Delegate records" : "Revoke record delegate" ) ;
179161 }
180162 const spinner = ora ( ) ;
163+ const ctx = buildDotnsContext ( context , {
164+ onStatus : makeOnStatus ( spinner , "Delegating record control to" ) ,
165+ } ) ;
181166
182167 const operatorAddress = await maybeQuiet ( jsonOutput , ( ) =>
183- resolveTransferRecipient ( context . clientWrapper ! , context . substrateAddress , operator ) ,
168+ resolveTransferRecipient ( ctx , operator ) ,
184169 ) ;
185170
186171 if ( ! jsonOutput ) {
187172 console . log ( chalk . gray ( " operator: " ) + chalk . white ( operatorAddress ) ) ;
188173 }
189174
190175 const result = await maybeQuiet ( jsonOutput , ( ) =>
191- setRecordDelegate (
192- context . clientWrapper ! ,
193- context . substrateAddress ,
194- context . signer ,
195- operatorAddress as Address ,
196- approved ,
197- spinner ,
198- ) ,
176+ setRecordDelegate ( ctx , operatorAddress as Address , approved ) ,
199177 ) ;
200178
201179 if ( ! emitJsonResult ( jsonOutput , result ) ) {
@@ -222,20 +200,16 @@ export function attachDelegateCommands(root: Command) {
222200 prepareReadOnlyContext ( mergedOptions as never ) ,
223201 ) ;
224202
225- if ( ! jsonOutput ) console . log ( chalk . bold ( "\n▶ Record delegate status\n" ) ) ;
203+ if ( ! jsonOutput ) printCommandHeader ( " Record delegate status" ) ;
226204 const spinner = ora ( ) ;
205+ const ctx = buildReadOnlyDotnsContext ( context , { onStatus : makeOnStatus ( spinner ) } ) ;
227206
228207 const operatorAddress = await maybeQuiet ( jsonOutput , ( ) =>
229- resolveTransferRecipient ( context . clientWrapper ! , context . account . address , operator ) ,
208+ resolveTransferRecipient ( ctx , operator ) ,
230209 ) ;
231210
232211 const approved = await maybeQuiet ( jsonOutput , ( ) =>
233- getRecordDelegate (
234- context . clientWrapper ! ,
235- context . account . address ,
236- operatorAddress as Address ,
237- spinner ,
238- ) ,
212+ getRecordDelegate ( ctx , operatorAddress as Address ) ,
239213 ) ;
240214
241215 if ( ! emitJsonResult ( jsonOutput , { operator : operatorAddress , approved } ) ) {
0 commit comments