Browse Source

add dates to frontend

master
nitowa 1 month ago
parent
commit
e9045436f3

+ 8
- 3
src/frontend/src/app/app.component.html View File

114
           <div class="card">
114
           <div class="card">
115
             <h3 class="card-header">
115
             <h3 class="card-header">
116
               {{shout.title}} 
116
               {{shout.title}} 
117
-              <a [href]="'https://testnet.xrpl.org/transactions/'+shout.hash+'/detailed'" target="_blank">
118
-                <cds-icon shape="link"></cds-icon>
119
-              </a>
117
+              <span class="p3">
118
+                <br />
119
+                ({{shout.date}}
120
+                <a [href]="'https://testnet.xrpl.org/transactions/'+shout.hash+'/detailed'" target="_blank">
121
+                  <cds-icon shape="link"></cds-icon>
122
+                </a>
123
+                )
124
+              </span>
120
             </h3>            
125
             </h3>            
121
             <div class="card-block">
126
             <div class="card-block">
122
               <div class="card-text">
127
               <div class="card-text">

+ 18
- 12
src/frontend/src/app/app.component.ts View File

1
-import { Component, OnInit } from '@angular/core';
1
+import { Component, NgZone, OnInit } from '@angular/core';
2
 import { ShoutboxDataService } from './services/ShoutboxData.service';
2
 import { ShoutboxDataService } from './services/ShoutboxData.service';
3
 import { makeTestnetWallet } from './util/TestnetUtils';
3
 import { makeTestnetWallet } from './util/TestnetUtils';
4
 
4
 
19
     title: "",
19
     title: "",
20
     body: "",
20
     body: "",
21
     from: "",
21
     from: "",
22
-    hash: ""
22
+    hash: "",
23
+    date: "",
23
   }
24
   }
24
   userWallet = {
25
   userWallet = {
25
     address: "",
26
     address: "",
31
   }
32
   }
32
 
33
 
33
   constructor(
34
   constructor(
34
-    private dataService: ShoutboxDataService
35
+    private dataService: ShoutboxDataService,
36
+    private zone: NgZone
35
   ) {
37
   ) {
36
     this.contractAddress = dataService.getContractAddress()
38
     this.contractAddress = dataService.getContractAddress()
37
   }
39
   }
44
           title: "",
46
           title: "",
45
           body: "",
47
           body: "",
46
           from: "",
48
           from: "",
47
-          hash: ""
49
+          hash: "",
50
+          date: "",
48
         }
51
         }
49
         this.lastMessageHash = hash
52
         this.lastMessageHash = hash
50
       })
53
       })
56
   }
59
   }
57
 
60
 
58
   ngOnInit() {
61
   ngOnInit() {
59
-    Promise.all([makeTestnetWallet(), makeTestnetWallet()]).then(([userWallet, drainWallet]) => {
60
-      console.log(userWallet, drainWallet)
61
-      this.userWallet = userWallet
62
-      this.drainWallet = drainWallet
62
+    Promise.all([makeTestnetWallet(), makeTestnetWallet()])
63
+      .then(async ([userWallet, drainWallet]) => {
64
+        this.userWallet = userWallet
65
+        this.drainWallet = drainWallet
63
 
66
 
64
-      this.dataService.initialize((shout: any) => {
65
-        this.shouts.unshift(shout)
67
+        await this.dataService.initialize((shout: any) => {
68
+          this.zone.run(_ => {
69
+            this.shouts.unshift(shout)
70
+            console.log(shout)
71
+          })
72
+        }, userWallet, drainWallet)
66
         this.initializing = false
73
         this.initializing = false
67
-      }, userWallet, drainWallet)
68
-    })
74
+      })
69
   }
75
   }
70
 }
76
 }

+ 29
- 28
src/frontend/src/app/services/ShoutboxData.service.ts View File

1
-import { Injectable } from "@angular/core";
1
+import { ChangeDetectorRef, Injectable, NgZone } from "@angular/core";
2
 import { z } from 'zod';
2
 import { z } from 'zod';
3
 
3
 
4
 declare const RJSVM: any;
4
 declare const RJSVM: any;
11
 @Injectable()
11
 @Injectable()
12
 export class ShoutboxDataService {
12
 export class ShoutboxDataService {
13
 
13
 
14
-    public history: any[] = []
15
     private dataWriter = undefined as any
14
     private dataWriter = undefined as any
16
 
15
 
16
+    constructor(
17
+    ) { }
18
+
17
     public submitShout = async (shout: any) => {
19
     public submitShout = async (shout: any) => {
18
         return await this.dataWriter.callEndpoint('submit', shout, 10)
20
         return await this.dataWriter.callEndpoint('submit', shout, 10)
19
     }
21
     }
20
 
22
 
21
     public getContractAddress = () => listeningAddress
23
     public getContractAddress = () => listeningAddress
22
 
24
 
23
-    initialize = async (onData:Function, userWallet?:any, drainWallet?:any) => {
25
+    initialize = async (onData: Function, userWallet?: any, drainWallet?: any) => {
24
 
26
 
25
         this.dataWriter = new Datawriter({
27
         this.dataWriter = new Datawriter({
26
             receiveAddress: drainWallet.address,
28
             receiveAddress: drainWallet.address,
33
             title: z.string(),
35
             title: z.string(),
34
             body: z.string(),
36
             body: z.string(),
35
             from: z.string(),
37
             from: z.string(),
38
+            hash: z.optional(z.string()),
39
+            date: z.optional(z.string()),
36
             id: z.optional(z.string())
40
             id: z.optional(z.string())
37
         })
41
         })
38
-        //type Shout = z.infer<typeof shoutSchema>
39
-    
40
-        type State = {
41
-            shouts: any[]
42
-        }
43
-    
42
+        type Shout = z.infer<typeof shoutSchema>
43
+
44
+        type State = {}
45
+
44
         // #########################
46
         // #########################
45
         // Define endpoints
47
         // Define endpoints
46
         // #########################
48
         // #########################
47
-    
49
+
48
         type RJSVM_Endpoints = {
50
         type RJSVM_Endpoints = {
49
-            submit: (data: any) => void
51
+            submit: (data: Shout) => void
50
         }
52
         }
51
-    
53
+
52
         // #########################
54
         // #########################
53
         // Define init state
55
         // Define init state
54
         // #########################
56
         // #########################
55
-    
57
+
56
         abstract class RJSVM_Base
58
         abstract class RJSVM_Base
57
             extends RJSVM<State, RJSVM_Endpoints>
59
             extends RJSVM<State, RJSVM_Endpoints>
58
-            {
59
-            
60
+        {
61
+
60
             owner = userWallet.address
62
             owner = userWallet.address
61
-    
62
-            state: State = {
63
-                shouts: []
64
-            }
63
+
64
+            state: State = {}
65
         }
65
         }
66
-    
66
+
67
         // #########################
67
         // #########################
68
         // Implement logic
68
         // Implement logic
69
         // #########################
69
         // #########################
70
-    
70
+
71
         const RJSVM_Contract = {
71
         const RJSVM_Contract = {
72
             submit: {
72
             submit: {
73
-                implementation: function (env:any, shout: any) {
73
+                implementation: function (env: any, shout: Shout) {
74
                     shout.hash = env.hash;
74
                     shout.hash = env.hash;
75
-                    (this as any).state.shouts.unshift(shout)
75
+                    const d = new Date("2000-01-01");
76
+                    d.setSeconds(d.getSeconds() + env.date)
77
+                    shout.date = d.toLocaleString("de-DE")
76
                 },
78
                 },
77
                 visibility: 'public',
79
                 visibility: 'public',
78
                 fee: 10,
80
                 fee: 10,
79
                 parameterSchema: shoutSchema
81
                 parameterSchema: shoutSchema
80
             }
82
             }
81
         }
83
         }
82
-    
84
+
83
         // #########################
85
         // #########################
84
         // Build and connect
86
         // Build and connect
85
         // #########################
87
         // #########################
86
-    
88
+
87
         const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract);
89
         const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract);
88
-    
90
+
89
         const conf = {
91
         const conf = {
90
             listeningAddress: listeningAddress,
92
             listeningAddress: listeningAddress,
91
             rippleNode: xrpNode
93
             rippleNode: xrpNode
92
         }
94
         }
93
-    
95
+
94
         const rjsvm = new Rjsvm(conf)
96
         const rjsvm = new Rjsvm(conf)
95
         await rjsvm.connect()
97
         await rjsvm.connect()
96
 
98
 
97
         rjsvm.on('error', console.log)
99
         rjsvm.on('error', console.log)
98
         rjsvm.on('submit', onData)
100
         rjsvm.on('submit', onData)
99
 
101
 
100
-        this.history = rjsvm.state.shouts
101
     }
102
     }
102
 }
103
 }

Loading…
Cancel
Save