@ -18,7 +18,7 @@
: to - project - id = "toProjectId"
: giver = "giver"
: receiver = "receiver"
: notify = "$ notify"
: notify = "notify"
@ entity - selected = "handleEntitySelected"
@ cancel = "cancel"
/ >
@ -62,17 +62,16 @@ import {
getHeaders ,
} from "../libs/endorserServer" ;
import * as libsUtil from "../libs/util" ;
/ / R e m o v e d u n u s e d i m p o r t s : d b , r e t r i e v e S e t t i n g s F o r A c t i v e A c c o u n t
import { Contact } from "../db/tables/contacts" ;
import * as databaseUtil from "../db/databaseUtil" ;
import { retrieveAccountDids } from "../libs/util" ;
import { logger } from "../utils/logger" ;
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory" ;
import EntityIcon from "../components/EntityIcon.vue" ;
import ProjectIcon from "../components/ProjectIcon.vue" ;
import EntitySelectionStep from "../components/EntitySelectionStep.vue" ;
import GiftDetailsStep from "../components/GiftDetailsStep.vue" ;
import { PlanData } from "../interfaces/records" ;
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin" ;
import { createNotifyHelpers , TIMEOUTS } from "@/utils/notify" ;
@ Component ( {
components : {
@ -81,9 +80,10 @@ import { PlanData } from "../interfaces/records";
EntitySelectionStep ,
GiftDetailsStep ,
} ,
mixins : [ PlatformServiceMixin ] ,
} )
export default class GiftedDialog extends Vue {
$ notify! : ( notification : NotificationIface , timeout ? : number ) => void ;
notify ! : ReturnType < typeof createNotifyHelpers > ;
@ Prop ( ) fromProjectId = "" ;
@ Prop ( ) toProjectId = "" ;
@ -230,17 +230,11 @@ export default class GiftedDialog extends Vue {
this . updateEntityTypes ( ) ;
try {
const settings = await databaseUtil . retrieveSettingsForActiveAccount ( ) ;
const settings = await this . $settings ( ) ;
this . apiServer = settings . apiServer || "" ;
this . activeDid = settings . activeDid || "" ;
const platformService = PlatformServiceFactory . getInstance ( ) ;
const result = await platformService . dbQuery ( ` SELECT * FROM contacts ` ) ;
if ( result ) {
this . allContacts = databaseUtil . mapQueryResultToValues (
result ,
) as unknown as Contact [ ] ;
}
this . allContacts = await this . $contacts ( ) ;
this . allMyDids = await retrieveAccountDids ( ) ;
@ -264,17 +258,11 @@ export default class GiftedDialog extends Vue {
}
} catch ( err : unknown ) {
logger . error ( "Error retrieving settings from database:" , err ) ;
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text :
err instanceof Error
? err . message
: "There was an error retrieving your settings." ,
} ,
- 1 ,
this . notify . error (
err instanceof Error
? err . message
: "There was an error retrieving your settings." ,
TIMEOUTS . MODAL ,
) ;
}
@ -319,68 +307,37 @@ export default class GiftedDialog extends Vue {
async confirm ( ) {
if ( ! this . activeDid ) {
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : "You must select an identifier before you can record a give." ,
} ,
3000 ,
this . notify . error (
"You must select an identifier before you can record a give." ,
TIMEOUTS . STANDARD ,
) ;
return ;
}
if ( parseFloat ( this . amountInput ) < 0 ) {
this . $notify (
{
group : "alert" ,
type : "danger" ,
text : "You may not send a negative number." ,
title : "" ,
} ,
2000 ,
) ;
this . notify . error ( "You may not send a negative number." , TIMEOUTS . SHORT ) ;
return ;
}
if ( ! this . description && ! parseFloat ( this . amountInput ) ) {
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : ` You must enter a description or some number of ${
this . libsUtil . UNIT_LONG [ this . unitCode ]
} . ` ,
} ,
2000 ,
this . notify . error (
` You must enter a description or some number of ${
this . libsUtil . UNIT_LONG [ this . unitCode ]
} . ` ,
TIMEOUTS . SHORT ,
) ;
return ;
}
/ / C h e c k f o r p e r s o n c o n f l i c t
if ( this . hasPersonConflict ) {
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : "You cannot select the same person as both giver and recipient." ,
} ,
3000 ,
this . notify . error (
"You cannot select the same person as both giver and recipient." ,
TIMEOUTS . STANDARD ,
) ;
return ;
}
this . close ( ) ;
this . $notify (
{
group : "alert" ,
type : "toast" ,
text : "Recording the give..." ,
title : "" ,
} ,
1000 ,
) ;
this . notify . toast ( "Recording the give..." , undefined , TIMEOUTS . BRIEF ) ;
/ / t h i s i s a s y n c h r o n o u s , b u t w e d o n ' t n e e d t o w a i t f o r i t t o c o m p l e t e
await this . recordGive (
( this . giver ? . did as string ) || null ,
@ -460,25 +417,12 @@ export default class GiftedDialog extends Vue {
if ( ! result . success ) {
const errorMessage = this . getGiveCreationErrorMessage ( result ) ;
logger . error ( "Error with give creation result:" , result ) ;
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : errorMessage || "There was an error creating the give." ,
} ,
- 1 ,
this . notify . error (
errorMessage || "There was an error creating the give." ,
TIMEOUTS . MODAL ,
) ;
} else {
this . $notify (
{
group : "alert" ,
type : "success" ,
title : "Success" ,
text : ` That gift was recorded. ` ,
} ,
7000 ,
) ;
this . notify . success ( "That gift was recorded." , TIMEOUTS . VERY_LONG ) ;
if ( this . callbackOnSuccess ) {
this . callbackOnSuccess ( amount ) ;
}
@ -490,15 +434,7 @@ export default class GiftedDialog extends Vue {
error . userMessage ||
serverMessageForUser ( error ) ||
"There was an error recording the give." ;
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : errorMessage ,
} ,
- 1 ,
) ;
this . notify . error ( errorMessage , TIMEOUTS . MODAL ) ;
}
}
@ -518,15 +454,7 @@ export default class GiftedDialog extends Vue {
}
explainData ( ) {
this . $notify (
{
group : "alert" ,
type : "success" ,
title : "Data Sharing" ,
text : libsUtil . PRIVACY_MESSAGE ,
} ,
- 1 ,
) ;
this . notify . info ( libsUtil . PRIVACY_MESSAGE , TIMEOUTS . MODAL ) ;
}
selectGiver ( contact ? : Contact ) {
@ -566,15 +494,7 @@ export default class GiftedDialog extends Vue {
}
} catch ( error ) {
logger . error ( "Error loading projects:" , error ) ;
this . $notify (
{
group : "alert" ,
type : "danger" ,
title : "Error" ,
text : "Failed to load projects" ,
} ,
3000 ,
) ;
this . notify . error ( "Failed to load projects" , TIMEOUTS . STANDARD ) ;
}
}
@ -696,6 +616,10 @@ export default class GiftedDialog extends Vue {
amountInput : this . amountInput ,
} ) ;
}
created ( ) {
this . notify = createNotifyHelpers ( this . $notify ) ;
}
}
< / script >