File tree Expand file tree Collapse file tree 2 files changed +22
-9
lines changed
Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Original file line number Diff line number Diff line change 1- import { jsPDF } from 'jspdf' ;
1+ import type { jsPDF } from 'jspdf' ;
22import * as QRCode from 'qrcode' ;
33import { IDrawKeyCard } from './types' ;
44import { splitKeys } from './utils' ;
5+ type jsPDFModule = typeof import ( 'jspdf' ) ;
6+
7+ async function loadJSPDF ( ) : Promise < jsPDFModule > {
8+ let jsPDF : jsPDFModule ;
9+
10+ if ( typeof window !== 'undefined' && typeof window . document !== 'undefined' ) {
11+ // We are in the browser
12+ jsPDF = await import ( 'jspdf' ) ;
13+ } else {
14+ // We are in Node.js
15+ jsPDF = require ( 'jspdf' ) ;
16+ }
17+ return jsPDF ;
18+ }
519
620enum KeyCurveName {
721 ed25519 = 'EDDSA' ,
@@ -97,12 +111,14 @@ export async function drawKeycard({
97111 walletLabel,
98112 curve,
99113} : IDrawKeyCard ) : Promise < jsPDF > {
114+ const jsPDFModule = await loadJSPDF ( ) ;
115+
100116 // document details
101117 const width = 8.5 * 72 ;
102118 let y = 0 ;
103119
104120 // Create the PDF instance
105- const doc = new jsPDF ( 'portrait' , 'pt' , 'letter' ) ; // jshint ignore:line
121+ const doc = new jsPDFModule . jsPDF ( 'portrait' , 'pt' , 'letter' ) ; // jshint ignore:line
106122 doc . setFont ( 'helvetica' ) ;
107123
108124 // PDF Header Area - includes the logo and company name
Original file line number Diff line number Diff line change 1- import jsPDF from 'jspdf' ;
2-
31import { generateQrData } from './generateQrData' ;
42import { generateFaq } from './faq' ;
53import { drawKeycard } from './drawKeycard' ;
@@ -13,17 +11,16 @@ export * from './utils';
1311export * from './types' ;
1412
1513export async function generateKeycard ( params : GenerateKeycardParams ) : Promise < void > {
16- let keycard : jsPDF ;
1714 if ( 'coin' in params ) {
1815 const questions = generateFaq ( params . coin . fullName ) ;
1916 const qrData = generateQrData ( params ) ;
20- keycard = await drawKeycard ( { ...params , questions, qrData } ) ;
17+ const keycard = await drawKeycard ( { ...params , questions, qrData } ) ;
18+ keycard . save ( `BitGo Keycard for ${ params . walletLabel } .pdf` ) ;
2119 } else if ( 'curve' in params ) {
2220 const data = generateParamsForKeyCreation ( params ) ;
23- keycard = await drawKeycard ( data ) ;
21+ const keycard = await drawKeycard ( data ) ;
22+ keycard . save ( `BitGo Keycard for ${ params . walletLabel } .pdf` ) ;
2423 } else {
2524 throw new Error ( 'Either curve or coin must be provided' ) ;
2625 }
27- // Save the PDF on the user's browser
28- keycard . save ( `BitGo Keycard for ${ params . walletLabel } .pdf` ) ;
2926}
You can’t perform that action at this time.
0 commit comments