5
5
formDataEntries ,
6
6
setClipboard ,
7
7
openBlobSVG ,
8
- sortContactsByAlias ,
8
+ // sortContactsByAlias,
9
9
// sortContactsByName,
10
10
parseAddressField ,
11
11
generateContactPairingURI ,
@@ -28,7 +28,7 @@ export let addContactRig = (async function (globals) {
28
28
let {
29
29
setupDialog, appDialogs, appState, appTools, store,
30
30
mainApp, wallet, userInfo, contactsList,
31
- updateAllFunds, walletFunds ,
31
+ updateAllFunds,
32
32
} = globals ;
33
33
34
34
let aliases = { }
@@ -164,6 +164,8 @@ export let addContactRig = (async function (globals) {
164
164
// )
165
165
}
166
166
167
+ let newContact
168
+
167
169
if ( existingContacts ?. length > 0 ) {
168
170
console . warn (
169
171
`You've already paired with this contact` ,
@@ -175,53 +177,75 @@ export let addContactRig = (async function (globals) {
175
177
}
176
178
}
177
179
)
178
- }
179
180
180
- let newContact = await appTools . storedData . encryptItem (
181
- store . contacts ,
182
- state . wallet . xkeyId ,
183
- {
184
- ...state . contact ,
185
- updatedAt : ( new Date ( ) ) . toISOString ( ) ,
186
- info : {
187
- ...OIDC_CLAIMS ,
188
- ...( state . contact . info || { } ) ,
189
- ...info ,
181
+ // newContact = existingContacts[0]
182
+
183
+ let pairings = existingContacts . map ( c => `@${ c . alias } ` )
184
+ if ( pairings . length > 1 ) {
185
+ let lastPairing = pairings . pop ( )
186
+ pairings = `${ pairings . join ( ', ' ) } & ${ lastPairing } `
187
+ } else {
188
+ pairings = pairings [ 0 ]
189
+ }
190
+
191
+ // TODO: maybe prompt to show original pairing info
192
+ // in the scenario where your contact
193
+ // lost their contacts list
194
+ target . contactAddr . setCustomValidity (
195
+ `You've already paired with this contact (@${ preferred_username } ) as ${ pairings } ` ,
196
+ )
197
+ target . reportValidity ( )
198
+ return ;
199
+ } else {
200
+ newContact = await appTools . storedData . encryptItem (
201
+ store . contacts ,
202
+ state . wallet . xkeyId ,
203
+ {
204
+ ...state . contact ,
205
+ updatedAt : ( new Date ( ) ) . toISOString ( ) ,
206
+ info : {
207
+ ...OIDC_CLAIMS ,
208
+ ...( state . contact . info || { } ) ,
209
+ ...info ,
210
+ } ,
211
+ outgoing,
212
+ alias : preferredAlias ,
213
+ uri : value ,
190
214
} ,
191
- outgoing,
192
- alias : preferredAlias ,
193
- uri : value ,
194
- } ,
195
- false ,
196
- )
215
+ false ,
216
+ )
197
217
198
- getStoreData (
199
- store . contacts ,
200
- res => {
201
- if ( res ) {
202
- appState . contacts = res
218
+ getStoreData (
219
+ store . contacts ,
220
+ res => {
221
+ if ( res ) {
222
+ appState . contacts = res
203
223
204
- return contactsList . restate ( {
205
- contacts : res ,
206
- userInfo,
207
- } )
224
+ return contactsList . restate ( {
225
+ contacts : res ,
226
+ userInfo,
227
+ } )
228
+ }
229
+ } ,
230
+ res => async v => {
231
+ res . push ( await appTools . storedData . decryptData ( v ) )
208
232
}
209
- } ,
210
- res => async v => {
211
- res . push ( await appTools . storedData . decryptData ( v ) )
212
- }
213
- )
233
+ )
214
234
215
- state . contact = newContact
235
+ state . contact = newContact
216
236
217
- if ( xkeyOrAddr ) {
218
- target . contactAddr . value = xkeyOrAddr
219
- }
220
- if ( name ) {
221
- target . contactName . value = name
222
- }
223
- if ( preferred_username ) {
224
- target . contactAlias . value = preferredAlias
237
+ if ( value ) {
238
+ target . contactURI . value = value
239
+ }
240
+ if ( xkeyOrAddr ) {
241
+ target . contactAddr . value = xkeyOrAddr
242
+ }
243
+ if ( name ) {
244
+ target . contactName . value = name
245
+ }
246
+ if ( preferred_username ) {
247
+ target . contactAlias . value = preferredAlias
248
+ }
225
249
}
226
250
227
251
return
@@ -303,6 +327,12 @@ export let addContactRig = (async function (globals) {
303
327
</ span >
304
328
</ button >
305
329
</ div >
330
+ < input
331
+ id ="contactURI "
332
+ type ="hidden "
333
+ name ="contactURI "
334
+ value =""
335
+ />
306
336
< p > Paste a Dash Address, Xprv/Xpub, or Link</ p >
307
337
308
338
< div class ="error "> </ div >
@@ -559,7 +589,7 @@ export let addContactRig = (async function (globals) {
559
589
sub : parsedAddr ?. sub || '' ,
560
590
name : event . target . contactName . value ,
561
591
} ,
562
- uri : event . target . contactAddr . value ,
592
+ uri : event . target . contactURI . value ,
563
593
alias : currentAlias || event . target . contactAlias . value ,
564
594
} ,
565
595
false ,
@@ -574,7 +604,7 @@ export let addContactRig = (async function (globals) {
574
604
if ( res ) {
575
605
appState . contacts = res
576
606
577
- updateAllFunds ( state . wallet , walletFunds )
607
+ updateAllFunds ( state . wallet )
578
608
. then ( funds => {
579
609
// console.log('updateAllFunds then funds', funds)
580
610
} )
0 commit comments