11<template >
22 <div class =" container" :class =" { popup: isPopup }" >
3- <div v-if =" network" class =" verify-transaction" >
3+ <div v-if =" initError" class =" verify-transaction__loading" >
4+ <p style =" color : #c00 ; text-align : center ; padding : 16px " >
5+ {{ initError }}
6+ </p >
7+ <div style =" display : flex ; justify-content : center ; margin-top : 16px " >
8+ <base-button title =" Go Back" :click =" close" :gray =" true" />
9+ </div >
10+ </div >
11+
12+ <div v-else-if =" network && txData" class =" verify-transaction" >
413 <custom-scrollbar
514 ref =" verifyScrollRef"
615 class =" verify-transaction__scroll-area"
6675 </div >
6776
6877 <send-process
69- v-if =" isProcessing"
78+ v-if =" isProcessing && txData && network "
7079 v-model =" isProcessing"
7180 :is-nft =" false"
7281 :to-address =" txData.toAddress"
7988</template >
8089
8190<script setup lang="ts">
82- import { onBeforeMount , ref , ComponentPublicInstance } from ' vue' ;
91+ import { onBeforeMount , ref , computed , ComponentPublicInstance } from ' vue' ;
8392import { useRoute , useRouter } from ' vue-router' ;
8493import CloseIcon from ' @action/icons/common/close-icon.vue' ;
8594import BaseButton from ' @action/components/base-button/index.vue' ;
@@ -102,46 +111,82 @@ import { trackSendEvents } from '@/libs/metrics';
102111import { SendEventType } from ' @/libs/metrics/types' ;
103112import sendUsingInternalMessengers from ' @/libs/messenger/internal-messenger' ;
104113import { InternalMethods } from ' @/types/messenger' ;
114+ import RecentlySentAddressesState from ' @/libs/recently-sent-addresses' ;
105115
106116const POPUP_CLOSE_DELAY = 4500 ;
107117const WINDOW_CLOSE_DELAY = 1500 ;
108118
109119const KeyRing = new PublicKeyRing ();
110120const route = useRoute ();
111121const router = useRouter ();
112- const selectedNetwork: string = route .query .id as string ;
113122
114- const txData: VerifyTransactionParams = JSON .parse (
115- Buffer .from (route .query .txData as string , ' base64' ).toString (' utf8' ),
116- );
123+ const selectedNetwork = ref <string >(' ' );
124+ const txData = ref <VerifyTransactionParams | null >(null );
117125
118126const isProcessing = ref (false );
119- const network = ref <ECashNetwork >( );
127+ const network = ref <ECashNetwork | null >( null );
120128const isSendDone = ref (false );
121- const account = ref <EnkryptAccount >( );
129+ const account = ref <EnkryptAccount | undefined >( undefined );
122130const isPopup: boolean = getCurrentContext () === ' new-window' ;
123131const verifyScrollRef = ref <ComponentPublicInstance <HTMLElement >>();
124132const isWindowPopup = ref (false );
125133const errorMsg = ref (' ' );
134+ const initError = ref (' ' );
126135
127136defineExpose ({ verifyScrollRef });
128137
129- import { computed } from ' vue' ;
130-
131138const displayFromAddress = computed (() => {
132- if (! network .value ) return ' ' ;
133- return network .value .displayAddress (txData .fromAddress );
139+ if (! network .value || ! txData . value ) return ' ' ;
140+ return network .value .displayAddress (txData .value . fromAddress );
134141});
135142
136143const isInPopupContext = computed (() => getCurrentContext () === ' popup' );
137144
138145onBeforeMount (async () => {
139- network .value = (await getNetworkByName (selectedNetwork )! ) as ECashNetwork ;
140- if (network .value ) {
146+ try {
147+ const rawId = route .query .id ;
148+ const rawTxData = route .query .txData ;
149+
150+ if (! rawId || typeof rawId !== ' string' ) {
151+ throw new Error (' Missing or invalid network id in route.' );
152+ }
153+ if (! rawTxData || typeof rawTxData !== ' string' ) {
154+ throw new Error (' Missing or invalid transaction data in route.' );
155+ }
156+
157+ selectedNetwork .value = rawId ;
158+ txData .value = JSON .parse (
159+ Buffer .from (rawTxData , ' base64' ).toString (' utf8' ),
160+ ) as VerifyTransactionParams ;
161+ } catch (e : any ) {
162+ initError .value = ` Could not load transaction data: ${e .message } ` ;
163+ return ;
164+ }
165+
166+ try {
167+ const resolvedNetwork = await getNetworkByName (selectedNetwork .value );
168+ if (! resolvedNetwork ) {
169+ throw new Error (` Unknown network: "${selectedNetwork .value }" ` );
170+ }
171+ network .value = resolvedNetwork as ECashNetwork ;
141172 trackSendEvents (SendEventType .SendVerify , { network: network .value .name });
173+ } catch (e : any ) {
174+ initError .value = ` Could not load network: ${e .message } ` ;
175+ return ;
176+ }
177+
178+ try {
179+ const resolvedAccount = await KeyRing .getAccount (txData .value ! .fromAddress );
180+ if (! resolvedAccount ) {
181+ throw new Error (
182+ ` Account not found for address: ${txData .value ! .fromAddress } ` ,
183+ );
184+ }
185+ account .value = resolvedAccount ;
186+ isWindowPopup .value = resolvedAccount .isHardware ;
187+ } catch (e : any ) {
188+ initError .value = ` Could not load account: ${e .message } ` ;
142189 }
143- account .value = await KeyRing .getAccount (txData .fromAddress );
144- isWindowPopup .value = account .value .isHardware ;
145190});
146191
147192const close = () => {
@@ -155,7 +200,6 @@ const close = () => {
155200const closeAfterSend = (delay : number ) => {
156201 setTimeout (() => {
157202 isProcessing .value = false ;
158-
159203 if (isInPopupContext .value ) {
160204 router .go (- 2 );
161205 } else {
@@ -166,25 +210,25 @@ const closeAfterSend = (delay: number) => {
166210
167211const createTxActivity = (): Activity => ({
168212 from: displayFromAddress .value ,
169- to: txData .toAddress ,
170- isIncoming: txData .fromAddress === txData .toAddress ,
213+ to: txData .value ! . toAddress ,
214+ isIncoming: txData .value ! . fromAddress === txData . value ! .toAddress ,
171215 network: network .value ! .name ,
172216 status: ActivityStatus .pending ,
173217 timestamp: new Date ().getTime (),
174218 token: {
175- decimals: txData .toToken .decimals ,
176- icon: txData .toToken .icon ,
177- name: txData .toToken .name ,
178- symbol: txData .toToken .symbol ,
179- price: txData .toToken .price ,
219+ decimals: txData .value ! . toToken .decimals ,
220+ icon: txData .value ! . toToken .icon ,
221+ name: txData .value ! . toToken .name ,
222+ symbol: txData .value ! . toToken .symbol ,
223+ price: txData .value ! . toToken .price ,
180224 },
181225 type: ActivityType .transaction ,
182- value: txData .toToken .amount ,
226+ value: txData .value ! . toToken .amount ,
183227 transactionHash: ' ' ,
184228});
185229
186230const sendAction = async () => {
187- if (! network .value || ! account .value ) return ;
231+ if (! network .value || ! account .value || ! txData . value ) return ;
188232
189233 isProcessing .value = true ;
190234 trackSendEvents (SendEventType .SendApprove , {
@@ -196,8 +240,8 @@ const sendAction = async () => {
196240
197241 try {
198242 const signParams: any = {
199- toAddress: txData .toAddress ,
200- amount: txData .toToken .amount ,
243+ toAddress: txData .value . toAddress ,
244+ amount: txData .value . toToken .amount ,
201245 account: account .value ,
202246 networkName: network .value .name ,
203247 };
@@ -213,25 +257,22 @@ const sendAction = async () => {
213257
214258 const { txid } = JSON .parse (result .result ! );
215259
260+ const recentlySentAddresses = new RecentlySentAddressesState ();
261+ await recentlySentAddresses .addRecentlySentAddress (
262+ network .value ,
263+ txData .value .toAddress ,
264+ );
265+
216266 trackSendEvents (SendEventType .SendComplete , {
217267 network: network .value .name ,
218268 });
219269
220- activityState .addActivities (
221- [
222- {
223- ... txActivity ,
224- transactionHash: txid ,
225- },
226- ],
227- {
228- address: displayFromAddress .value ,
229- network: network .value .name ,
230- },
231- );
270+ activityState .addActivities ([{ ... txActivity , transactionHash: txid }], {
271+ address: displayFromAddress .value ,
272+ network: network .value .name ,
273+ });
232274
233275 isSendDone .value = true ;
234-
235276 const delay = isInPopupContext .value
236277 ? POPUP_CLOSE_DELAY
237278 : WINDOW_CLOSE_DELAY ;
@@ -244,7 +285,7 @@ const sendAction = async () => {
244285
245286 txActivity .status = ActivityStatus .failed ;
246287 activityState .addActivities ([txActivity ], {
247- address: txData .fromAddress ,
288+ address: txData .value . fromAddress ,
248289 network: network .value .name ,
249290 });
250291
0 commit comments