Skip to content

Commit aaed7c2

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

File tree

3 files changed

+97
-53
lines changed

3 files changed

+97
-53
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: 73 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ 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(),
1120
gasLimit: Yup.number()
1221
.typeError('Gas limit must be a number')
@@ -16,7 +25,11 @@ const validationSchema = Yup.object({
1625
maxFeePerGas: Yup.number().required(),
1726
maxPriorityFeePerGas: Yup.number().required(),
1827
recoveryDestination: Yup.string().required(),
19-
userKey: Yup.string().required(),
28+
userKey: Yup.string().when('isTss', {
29+
is: false,
30+
then: Yup.string().required(),
31+
otherwise: Yup.string().notRequired(),
32+
}),
2033
userKeyId: Yup.string(),
2134
walletContractAddress: Yup.string().required(),
2235
isTss: Yup.boolean(),
@@ -39,6 +52,7 @@ export function EthLikeForm({ onSubmit, coinName }: EthLikeFormProps) {
3952
apiKey: '',
4053
backupKey: '',
4154
backupKeyId: '',
55+
bitgoKey: '',
4256
gasLimit: allCoinMetas[coinName]?.defaultGasLimitNum ?? 500000,
4357
maxFeePerGas: 20,
4458
maxPriorityFeePerGas: 10,
@@ -57,38 +71,63 @@ export function EthLikeForm({ onSubmit, coinName }: EthLikeFormProps) {
5771
<h4 className="tw-text-body tw-font-semibold tw-border-b-0.5 tw-border-solid tw-border-gray-700 tw-mb-4">
5872
Self-managed cold wallet details
5973
</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>
74+
{allCoinMetas[coinName].isTssSupported && (
75+
<div className="tw-mb-4" role="group">
76+
<label>
77+
<Field type="checkbox" name="isTss" />
78+
Is TSS recovery?
79+
</label>
80+
</div>
81+
)}
82+
{formik.values.isTss ? null : (
83+
<div>
84+
<div className="tw-mb-4">
85+
<FormikTextfield
86+
HelperText="Your user public key, as found on your recovery KeyCard."
87+
Label="User Public Key"
88+
name="userKey"
89+
Width="fill"
90+
/>
91+
</div>
92+
<div className="tw-mb-4">
93+
<FormikTextfield
94+
HelperText="Your user Key ID, as found on your KeyCard. Most wallets will not have this and you can leave it blank."
95+
Label="User Key ID (optional)"
96+
name="userKeyId"
97+
Width="fill"
98+
/>
99+
</div>
100+
<div className="tw-mb-4">
101+
<FormikTextfield
102+
HelperText="The backup public key for the wallet, as found on your recovery KeyCard."
103+
Label="Backup Public Key"
104+
name="backupKey"
105+
Width="fill"
106+
/>
107+
</div>
108+
<div className="tw-mb-4">
109+
<FormikTextfield
110+
HelperText="Your backup Key ID, as found on your KeyCard. Most wallets will not have this and you can leave it blank."
111+
Label="Backup Key ID (optional)"
112+
name="backupKeyId"
113+
Width="fill"
114+
/>
115+
</div>
116+
</div>
117+
)}
118+
{formik.values.isTss ? (
119+
<div>
120+
<div className="tw-mb-4">
121+
<FormikTextfield
122+
HelperText="Your BitGo public key, also known as the common keychain public key."
123+
Label="BitGo Public Key"
124+
name="bitgoKey"
125+
Width="fill"
126+
/>
127+
</div>
128+
</div>
129+
) : null
130+
}
92131
<div className="tw-mb-4">
93132
<FormikTextfield
94133
HelperText="The ETH address of the wallet contract. This is also the wallet's base address."
@@ -143,14 +182,6 @@ export function EthLikeForm({ onSubmit, coinName }: EthLikeFormProps) {
143182
Width="fill"
144183
/>
145184
</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-
)}
154185
<div className="tw-flex tw-flex-col-reverse sm:tw-justify-between sm:tw-flex-row tw-gap-1 tw-mt-4">
155186
<Button Tag={Link} to="/" Variant="secondary" Width="hug">
156187
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)