@@ -18,6 +18,7 @@ import {
1818import * as fcl from "@onflow/fcl"
1919import * as FlowTypes from "@onflow/types"
2020import { PURCHASE } from "flow/transactions/transaction.purchase"
21+ import { PURCHASE_PACK_TYPE } from "flow/transactions/transaction.purchase-pack-type"
2122import { toast } from "react-toastify"
2223import { toastStatus } from "@framework/helpers/toastStatus"
2324
@@ -114,10 +115,56 @@ export default function useFUSD(user: any) {
114115 }
115116 }
116117
118+ const purchasePackType = async ( amount : any , address : any , type : any ) => {
119+ dispatch ( { type : "PROCESSING" } )
120+
121+ const id = toast . loading ( "Initializing..." )
122+
123+ try {
124+ const res = await send ( [
125+ transaction ( PURCHASE_PACK_TYPE ) ,
126+ args ( [
127+ arg ( amount , FlowTypes . UFix64 ) ,
128+ arg ( address , FlowTypes . Address ) ,
129+ arg ( type , FlowTypes . String ) ,
130+ ] ) ,
131+ payer ( authz ) ,
132+ proposer ( authz ) ,
133+ authorizations ( [ authz ] ) ,
134+ limit ( 9999 ) ,
135+ ] ) . then ( decode )
136+ tx ( res ) . subscribe ( ( res : any ) => {
137+ toastStatus ( id , res . status )
138+ } )
139+ const trx = await tx ( res )
140+ . onceSealed ( )
141+ . then ( ( result : any ) => {
142+ toast . update ( id , {
143+ render : "Transaction Sealed" ,
144+ type : "success" ,
145+ isLoading : false ,
146+ autoClose : 5000 ,
147+ } )
148+ } )
149+ getFUSDBalance ( )
150+ return trx
151+ } catch ( err ) {
152+ toast . update ( id , {
153+ render : "Error, try again later..." ,
154+ type : "error" ,
155+ isLoading : false ,
156+ autoClose : 5000 ,
157+ } )
158+ dispatch ( { type : "ERROR" } )
159+ console . log ( err )
160+ }
161+ }
162+
117163 return {
118164 ...state ,
119165 getFUSDBalance,
120166 purchase,
121167 getUserFUSDBalance,
168+ purchasePackType,
122169 }
123170}
0 commit comments