Skip to content

Commit d93aed0

Browse files
committed
fix(wrw): refactor unsigned sweep flow to change exposed fields depending on isTSS
1 parent 429c851 commit d93aed0

File tree

3 files changed

+115
-61
lines changed

3 files changed

+115
-61
lines changed

src/containers/BuildUnsignedSweepCoin/BuildUnsignedSweepCoin.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function Form() {
143143
chain: getEthLikeRecoveryChainId(coin, bitGoEnvironment),
144144
hardfork: 'london',
145145
},
146-
bitgoKey: '',
146+
bitgoKey: values.bitgoKey || '',
147147
ignoreAddressTypes: [],
148148
});
149149
assert(

src/containers/BuildUnsignedSweepCoin/EthLikeForm.tsx

Lines changed: 91 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@ import { allCoinMetas } from '~/helpers/config';
66

77
const validationSchema = Yup.object({
88
apiKey: Yup.string().required(),
9-
backupKey: Yup.string().required(),
9+
backupKey: Yup.string().when('isTss', {
10+
is: false,
11+
then: Yup.string().required(),
12+
otherwise: Yup.string().notRequired(),
13+
}),
14+
bitgoKey: Yup.string().when('isTss', {
15+
is: true,
16+
then: Yup.string().required(),
17+
otherwise: Yup.string().notRequired(),
18+
}),
1019
backupKeyId: Yup.string(),
20+
seed: Yup.string(),
1121
gasLimit: Yup.number()
1222
.typeError('Gas limit must be a number')
1323
.integer()
@@ -16,7 +26,11 @@ const validationSchema = Yup.object({
1626
maxFeePerGas: Yup.number().required(),
1727
maxPriorityFeePerGas: Yup.number().required(),
1828
recoveryDestination: Yup.string().required(),
19-
userKey: Yup.string().required(),
29+
userKey: Yup.string().when('isTss', {
30+
is: false,
31+
then: Yup.string().required(),
32+
otherwise: Yup.string().notRequired(),
33+
}),
2034
userKeyId: Yup.string(),
2135
walletContractAddress: Yup.string().required(),
2236
isTss: Yup.boolean(),
@@ -39,6 +53,8 @@ export function EthLikeForm({ onSubmit, coinName }: EthLikeFormProps) {
3953
apiKey: '',
4054
backupKey: '',
4155
backupKeyId: '',
56+
bitgoKey: '',
57+
seed: '',
4258
gasLimit: allCoinMetas[coinName]?.defaultGasLimitNum ?? 500000,
4359
maxFeePerGas: 20,
4460
maxPriorityFeePerGas: 10,
@@ -57,46 +73,79 @@ export function EthLikeForm({ onSubmit, coinName }: EthLikeFormProps) {
5773
<h4 className="tw-text-body tw-font-semibold tw-border-b-0.5 tw-border-solid tw-border-gray-700 tw-mb-4">
5874
Self-managed cold wallet details
5975
</h4>
60-
<div className="tw-mb-4">
61-
<FormikTextfield
62-
HelperText="Your user public key, as found on your recovery KeyCard."
63-
Label="User Public Key"
64-
name="userKey"
65-
Width="fill"
66-
/>
67-
</div>
68-
<div className="tw-mb-4">
69-
<FormikTextfield
70-
HelperText="Your user Key ID, as found on your KeyCard. Most wallets will not have this and you can leave it blank."
71-
Label="User Key ID (optional)"
72-
name="userKeyId"
73-
Width="fill"
74-
/>
75-
</div>
76-
<div className="tw-mb-4">
77-
<FormikTextfield
78-
HelperText="The backup public key for the wallet, as found on your recovery KeyCard."
79-
Label="Backup Public Key"
80-
name="backupKey"
81-
Width="fill"
82-
/>
83-
</div>
84-
<div className="tw-mb-4">
85-
<FormikTextfield
86-
HelperText="Your backup Key ID, as found on your KeyCard. Most wallets will not have this and you can leave it blank."
87-
Label="Backup Key ID (optional)"
88-
name="backupKeyId"
89-
Width="fill"
90-
/>
91-
</div>
92-
<div className="tw-mb-4">
93-
<FormikTextfield
94-
HelperText="The ETH address of the wallet contract. This is also the wallet's base address."
95-
Label="Wallet Contract Address"
96-
name="walletContractAddress"
97-
Width="fill"
98-
/>
99-
</div>
76+
{allCoinMetas[coinName].isTssSupported && (
77+
<div className="tw-mb-4" role="group">
78+
<label>
79+
<Field type="checkbox" name="isTss" />
80+
Is TSS recovery?
81+
</label>
82+
</div>
83+
)}
84+
{formik.values.isTss ? null : (
85+
<div>
86+
<div className="tw-mb-4">
87+
<FormikTextfield
88+
HelperText="Your user public key, as found on your recovery KeyCard."
89+
Label="User Public Key"
90+
name="userKey"
91+
Width="fill"
92+
/>
93+
</div>
94+
<div className="tw-mb-4">
95+
<FormikTextfield
96+
HelperText="Your user Key ID, as found on your KeyCard. Most wallets will not have this and you can leave it blank."
97+
Label="User Key ID (optional)"
98+
name="userKeyId"
99+
Width="fill"
100+
/>
101+
</div>
102+
<div className="tw-mb-4">
103+
<FormikTextfield
104+
HelperText="The backup public key for the wallet, as found on your recovery KeyCard."
105+
Label="Backup Public Key"
106+
name="backupKey"
107+
Width="fill"
108+
/>
109+
</div>
110+
<div className="tw-mb-4">
111+
<FormikTextfield
112+
HelperText="Your backup Key ID, as found on your KeyCard. Most wallets will not have this and you can leave it blank."
113+
Label="Backup Key ID (optional)"
114+
name="backupKeyId"
115+
Width="fill"
116+
/>
117+
</div>
118+
<div className="tw-mb-4">
119+
<FormikTextfield
120+
HelperText="The ETH address of the wallet contract. This is also the wallet's base address."
121+
Label="Wallet Contract Address"
122+
name="walletContractAddress"
123+
Width="fill"
124+
/>
125+
</div>
126+
</div>
127+
)}
128+
{formik.values.isTss ? (
129+
<div>
130+
<div className="tw-mb-4">
131+
<FormikTextfield
132+
HelperText="Your BitGo public key, also known as the common keychain public key."
133+
Label="BitGo Public Key"
134+
name="bitgoKey"
135+
Width="fill"
136+
/>
137+
</div>
138+
<div className="tw-mb-4">
139+
<FormikTextfield
140+
HelperText="Your user seed as found on your KeyCard as Key ID. Most wallets will not have this and you can leave it blank."
141+
Label="Seed (optional)"
142+
name="seed"
143+
Width="fill"
144+
/>
145+
</div>
146+
</div>
147+
) : null
148+
}
100149
<div className="tw-mb-4">
101150
<FormikTextfield
102151
HelperText="The address your recovery transaction will send to."
@@ -143,14 +192,6 @@ export function EthLikeForm({ onSubmit, coinName }: EthLikeFormProps) {
143192
Width="fill"
144193
/>
145194
</div>
146-
{allCoinMetas[coinName].isTssSupported && (
147-
<div className="tw-mb-4" role="group">
148-
<label>
149-
<Field type="checkbox" name="isTss" />
150-
Is TSS recovery?
151-
</label>
152-
</div>
153-
)}
154195
<div className="tw-flex tw-flex-col-reverse sm:tw-justify-between sm:tw-flex-row tw-gap-1 tw-mt-4">
155196
<Button Tag={Link} to="/" Variant="secondary" Width="hug">
156197
Cancel

src/helpers/index.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,24 @@ export function mapSdkErrorToAlert(message: string): string {
108108

109109
export async function includePubsFor<
110110
TValues extends {
111-
userKey: string;
111+
userKey?: string;
112112
userKeyId?: string;
113-
backupKey: string;
113+
backupKey?: string;
114114
backupKeyId?: string;
115115
bitgoKey?: string;
116116
}
117117
>(coin: string, values: TValues) {
118+
if (!values.userKey && !values.backupKey && !values.bitgoKey) {
119+
throw new Error('No keys provided');
120+
}
121+
const userKey = values.userKey || values.bitgoKey;
122+
const backupKey = values.backupKey || values.bitgoKey;
123+
118124
const userXpub = values.userKeyId
119125
? (
120126
await window.queries.deriveKeyWithSeed(
121127
coin,
122-
values.userKey,
128+
userKey!,
123129
values.userKeyId
124130
)
125131
).key
@@ -128,7 +134,7 @@ export async function includePubsFor<
128134
? (
129135
await window.queries.deriveKeyWithSeed(
130136
coin,
131-
values.backupKey,
137+
backupKey!,
132138
values.backupKeyId
133139
)
134140
).key
@@ -183,10 +189,11 @@ export async function isDerivationPath(id: string, description: string) {
183189
}
184190

185191
export type UpdateKeysFromsIdsDefaultParams = {
186-
userKey: string;
192+
userKey?: string;
187193
userKeyId?: string;
188194
backupKeyId?: string;
189-
backupKey: string;
195+
backupKey?: string;
196+
bitgoKey?: string;
190197
}
191198

192199
export async function updateKeysFromIds<
@@ -196,16 +203,22 @@ export async function updateKeysFromIds<
196203
params: TParams,
197204
): Promise<Omit<TParams, 'userKeyId' | 'backupKeyId'>> {
198205
const { userKeyId, backupKeyId, ...copy } = params;
206+
if (!copy.bitgoKey && !copy.userKey && !copy.backupKey) {
207+
throw new Error('No keys provided');
208+
}
209+
// Either both userKey and backupKey are provided, or only bitgoKey is provided.
210+
const userKey = copy.userKey || copy.bitgoKey;
211+
const backupKey = copy.backupKey || copy.bitgoKey;
199212
const data = [
200213
{
201214
id: userKeyId,
202-
key: copy.userKey,
215+
key: userKey,
203216
description: 'User Key Id',
204217
name: 'userKey',
205218
},
206219
{
207220
id: backupKeyId,
208-
key: copy.backupKey,
221+
key: backupKey,
209222
description: 'Backup Key Id',
210223
name: 'backupKey',
211224
},
@@ -215,12 +228,12 @@ export async function updateKeysFromIds<
215228
if (item.id) {
216229
if (await isDerivationPath(item.id, item.description)) {
217230
copy[item.name] = await window.queries.deriveKeyByPath(
218-
item.key,
231+
item.key!,
219232
item.id,
220233
);
221234
} else {
222235
copy[item.name] = (
223-
await window.queries.deriveKeyWithSeed(coin, item.key, item.id)
236+
await window.queries.deriveKeyWithSeed(coin, item.key!, item.id)
224237
).key;
225238
}
226239
}

0 commit comments

Comments
 (0)