1
1
<script lang="ts" setup>
2
- import { MsgSend , type Msgs , type TxResponse } from ' @injectivelabs/sdk-ts'
3
- import { ref } from ' vue'
4
-
5
- const { address, sendTx, logout } = defineProps <{
6
- address: string
7
- sendTx: (msgs : Msgs ) => Promise <TxResponse >
8
- logout? : () => Promise <void >
9
- }>()
10
-
11
- const to = ref (address )
12
- const from = ref (address )
13
- const amount = ref (' 1000000' )
14
- // const amount = ref('1')
15
- const denom = ref (
16
- ' factory/inj1dm0yt646fsjsvznjz2twyht9ytcmwz3aqydjjp/RealTrumPepe' ,
17
- )
18
- // const denom = ref('inj')
2
+ import { getEthereumAddress , MsgSend } from ' @injectivelabs/sdk-ts'
3
+ import { onMounted , ref } from ' vue'
4
+ import { address , turnkeyStrategy , broadcaster , oidcToken } from ' ../reactives'
5
+ import { generateGoogleUrl } from ' ../utils'
6
+
7
+ const msgValues = ref ({
8
+ to: address .value ,
9
+ from: address .value ,
10
+ amount: ' 1000000' ,
11
+ denom: ' factory/inj1dm0yt646fsjsvznjz2twyht9ytcmwz3aqydjjp/RealTrumPepe' ,
12
+ })
19
13
20
14
const txHash = ref (' ' )
21
15
22
16
const isLoading = ref (false )
23
17
24
- const handleSubmit = async () => {
25
- console .log (' to' , to .value )
26
- console .log (' amount' , amount .value )
27
-
28
- if (! to .value || ! amount .value || ! denom .value ) {
18
+ const handleSendClick = async () => {
19
+ if (
20
+ ! msgValues .value .to ||
21
+ ! msgValues .value .from ||
22
+ ! msgValues .value .amount ||
23
+ ! msgValues .value .denom
24
+ ) {
29
25
throw new Error (' Invalid input' )
30
26
}
31
27
28
+ if (! address .value ) {
29
+ throw new Error (' Address not initialized' )
30
+ }
31
+
32
+ if (! broadcaster .value ) {
33
+ throw new Error (' Broadcaster not initialized' )
34
+ }
35
+
32
36
isLoading .value = true
33
37
34
38
const msgs = MsgSend .fromJSON ({
35
- srcInjectiveAddress: from .value ,
36
- dstInjectiveAddress: to .value ,
39
+ srcInjectiveAddress: msgValues .value . from ,
40
+ dstInjectiveAddress: msgValues .value . to ,
37
41
amount: [
38
42
{
39
- denom: denom .value ,
40
- amount: amount .value ,
43
+ denom: msgValues .value . denom ,
44
+ amount: msgValues .value . amount ,
41
45
},
42
46
],
43
47
})
44
48
45
49
try {
46
- const result = await sendTx (msgs )
50
+ const result = await broadcaster .value .broadcastWithFeeDelegation ({
51
+ msgs ,
52
+ injectiveAddress: address .value ,
53
+ ethereumAddress: getEthereumAddress (address .value ),
54
+ })
55
+
56
+ console .log (' 🪵 | result:' , result )
47
57
if (result .txHash ) {
48
58
txHash .value = result .txHash
49
59
}
@@ -53,11 +63,70 @@ const handleSubmit = async () => {
53
63
isLoading .value = false
54
64
}
55
65
}
66
+
67
+ async function deleteOrganization() {
68
+ if (! turnkeyStrategy .value ?.authIframeClient ) {
69
+ throw new Error (' Auth iframe client not initialized' )
70
+ }
71
+
72
+ const result =
73
+ await turnkeyStrategy .value .authIframeClient .deleteSubOrganization ({
74
+ deleteWithoutExport: true ,
75
+ organizationId: turnkeyStrategy .value .organizationId ,
76
+ timestampMs: Date .now ().toString (),
77
+ })
78
+ console .log (' 🪵 | deleteOrganization | result:' , result )
79
+ }
80
+
81
+ async function addGoogleOAuth() {
82
+ if (! turnkeyStrategy .value ?.authIframeClient ) {
83
+ throw new Error (' Auth iframe client not initialized' )
84
+ }
85
+ const nonce = await turnkeyStrategy .value .generateOAuthNonce ()
86
+
87
+ const googleUrl = generateGoogleUrl (nonce )
88
+
89
+ window .location .href = googleUrl
90
+ }
91
+
92
+ async function updateUserWithToken(oidcToken : string ) {
93
+ if (! turnkeyStrategy .value ?.authIframeClient ) {
94
+ throw new Error (' Auth iframe client not initialized' )
95
+ }
96
+
97
+ const user = await turnkeyStrategy .value .turnkey .getCurrentUser ()
98
+
99
+ if (! user ) {
100
+ throw new Error (' User not found' )
101
+ }
102
+
103
+ const result =
104
+ await turnkeyStrategy .value .authIframeClient .createOauthProviders ({
105
+ organizationId: turnkeyStrategy .value .organizationId ,
106
+ userId: user ?.userId ,
107
+ oauthProviders: [{ providerName: ' google' , oidcToken }],
108
+ })
109
+
110
+ console .log (' 🪵 | updateUserWithToken | result:' , result )
111
+
112
+ // Clear all params from URL either way
113
+ window .history .replaceState ({}, ' ' , window .location .pathname )
114
+ }
115
+
116
+ onMounted (async () => {
117
+ if (oidcToken .value ) {
118
+ updateUserWithToken (oidcToken .value )
119
+ }
120
+ })
56
121
</script >
57
122
58
123
<template >
59
124
<h2 >Connected!</h2 >
60
- <button @click =" logout" >Logout</button >
125
+ <div class =" actions" >
126
+ <button @click =" turnkeyStrategy?.disconnect()" >Logout</button >
127
+ <button @click =" deleteOrganization" >Delete Organization (Account)</button >
128
+ <button @click =" addGoogleOAuth" >Add Google OAuth</button >
129
+ </div >
61
130
<div >
62
131
<span >Addresses: {{ address }}</span >
63
132
</div >
@@ -66,17 +135,21 @@ const handleSubmit = async () => {
66
135
<form >
67
136
<label >
68
137
<span >To</span >
69
- <input type =" text" v-model =" to" />
138
+ <input type =" text" v-model =" msgValues. to" />
70
139
</label >
71
140
<label >
72
141
<span >Amount</span >
73
- <input type =" text" v-model =" amount" />
142
+ <input type =" text" v-model =" msgValues. amount" />
74
143
</label >
75
144
<label >
76
145
<span >Denom</span >
77
- <input type =" text" v-model =" denom" />
146
+ <input type =" text" v-model =" msgValues. denom" />
78
147
</label >
79
- <button type =" submit" @click.prevent =" handleSubmit" :disabled =" isLoading" >
148
+ <button
149
+ type =" submit"
150
+ @click.prevent =" handleSendClick"
151
+ :disabled =" isLoading"
152
+ >
80
153
{{ isLoading ? 'Sending...' : 'Submit' }}
81
154
</button >
82
155
<div v-if =" txHash" >
@@ -88,7 +161,13 @@ const handleSubmit = async () => {
88
161
</form >
89
162
</template >
90
163
91
- <style >
164
+ <style scoped>
165
+ .actions {
166
+ display : flex ;
167
+ gap : 10px ;
168
+ padding-bottom : 10px ;
169
+ }
170
+
92
171
form {
93
172
display : flex ;
94
173
flex-direction : column ;
0 commit comments