11console . log ( "welcome to minifirefly!" )
22
3- const API = window [ "__MINIFIREFLY__" ] ;
4- console . log ( "api -> " , API )
3+ const preload = window [ "__MINIFIREFLY__" ] ;
4+
5+ window [ "api" ] = { }
6+
7+ const handle = window [ "api" ]
8+
9+ // ---
10+
11+ const removeWallet = ( ) => {
12+ preload . removeWallet ( )
13+ window [ "_wallet" ] = null
14+ console . log ( "👋 REMOVED wallet" )
15+ }
16+ handle [ "removeWallet" ] = removeWallet
517
618// ---
719
820const createWallet = ( ) => {
9- API . createWallet ( ) . then ( ( wallet ) => {
21+ preload . createWallet ( ) . then ( ( wallet ) => {
1022 window [ "_wallet" ] = wallet
11- console . log ( "created wallet: " , wallet )
23+ console . log ( "🆕 CREATED wallet: " , wallet )
1224 } )
1325}
14- window [ "createWallet" ] = createWallet
15- console . log ( "createWallet -> " , createWallet )
26+ handle [ "createWallet" ] = createWallet
27+
28+ // ---
29+
30+ const loadWallet = ( ) => {
31+ preload . loadWallet ( ) . then ( ( wallet ) => {
32+ window [ "_wallet" ] = wallet
33+ console . log ( "🔄 LOADED wallet: " , wallet )
34+ } )
35+ }
36+ handle [ "loadWallet" ] = loadWallet
37+
1638
1739// ---
1840
1941const implicitAccountCreationAddress = ( ) => {
2042 window [ "_wallet" ] . implicitAccountCreationAddress ( ) . then ( ( address ) => {
21- console . log ( "send funds to " , address ) ;
43+ console . log ( "💸 SEND funds to " , address ) ;
2244 window [ "address" ] = address
2345 } )
2446}
25- window [ "implicitAccountCreationAddress" ] = implicitAccountCreationAddress
26- console . log ( "implicitAccountCreationAddress -> " , implicitAccountCreationAddress )
47+ handle [ "implicitAccountCreationAddress" ] = implicitAccountCreationAddress
2748
2849// ---
2950
3051const sync = ( ) => {
31- window [ "_wallet" ] . sync ( { syncImplicitAccounts : true } ) . then ( ( ) => {
32- console . log ( "synched wallet" )
52+ window [ "_wallet" ] . sync ( { syncImplicitAccounts : true } ) . then ( async ( ) => {
53+ console . log ( "📡 SYNCHED wallet" , ( await window [ "_wallet" ] . getBalance ( ) ) . baseCoin )
3354 } )
3455}
35- window [ "sync" ] = sync
36- console . log ( "sync -> " , sync )
56+ handle [ "sync" ] = sync
3757
3858// ---
3959
4060const implicitAccounts = ( ) => {
4161 window [ "_wallet" ] . implicitAccounts ( ) . then ( ( implicitAccounts ) => {
4262 window [ "_implicitAccounts" ] = implicitAccounts
43- console . log ( "implicitAccounts" , implicitAccounts )
63+ console . log ( "✅ implicitAccounts" , implicitAccounts )
4464 } )
4565}
46- window [ "implicitAccounts" ] = implicitAccounts
47- console . log ( "implicitAccounts -> " , implicitAccounts )
66+ handle [ "implicitAccounts" ] = implicitAccounts
4867
4968// ---
5069
5170const prepareImplicitAccountTransition = ( ) => {
5271 window [ "_wallet" ] . prepareImplicitAccountTransition ( window [ "_implicitAccounts" ] [ 0 ] . outputId ) . then ( ( res ) => {
53- console . log ( "res of prepareImplicitAccountTransition" , res )
72+ console . log ( "✅✅ prepareImplicitAccountTransition" , res )
5473 } )
5574}
56- window [ "prepareImplicitAccountTransition" ] = prepareImplicitAccountTransition
57- console . log ( "prepareImplicitAccountTransition -> " , prepareImplicitAccountTransition )
75+ handle [ "prepareImplicitAccountTransition" ] = prepareImplicitAccountTransition
76+
77+ setTimeout ( async ( ) => {
78+ console . clear ( )
79+
80+ console . log ( `
81+ Use the 'api' object with these methods:
82+
83+ 1. createWallet / loadWallet / removeWallet
84+ 2. implicitAccountCreationAddress
85+ 3. sync
86+ 4. implicitAccounts
87+ 5. prepareImplicitAccountTransition
88+ ` )
89+ } , 100 )
0 commit comments