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,9 +114,14 @@
114 114
           <div class="card">
115 115
             <h3 class="card-header">
116 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 125
             </h3>            
121 126
             <div class="card-block">
122 127
               <div class="card-text">

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

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

Loading…
Cancel
Save