{% extends "public.html" %} {% block toolbar_title %} Rotate Keys For {{
domain.domain }} {% endblock %} {% from "macros.jinja" import window_vars with
context %} {% block page %}
<link rel="stylesheet" href="/nostrnip5/static/css/signup.css" />
<div>
  <q-card class="q-pa-lg q-pt-lg">
    <q-form @submit="updateAddress" class="q-gutter-md">
      <p>
        You can use this page to change the public key associated with your
        NIP-5 identity.
      </p>
      <p>
        Your current NIP-5 identity is {{ address.local_part }}@{{ domain.domain
        }} with nostr public key {{ address.pubkey }}.
      </p>

      <p>Input your new pubkey below to update it.</p>

      <q-input
        filled
        dense
        v-model.trim="formDialog.data.pubkey"
        label="Pub Key"
        placeholder="abc234"
        :rules="[ val => val.length = 64 || val.indexOf('npub') === 0 ||'Please enter a hex pubkey' ]"
      >
      </q-input>

      <div class="row q-mt-lg">
        <q-btn
          unelevated
          color="primary"
          :disable="formDialog.data.pubkey == null"
          type="submit"
          >Rotate Keys</q-btn
        >
      </div>
    </q-form>
  </q-card>
</div>
{% endblock %} {% block scripts %}
<script>
  Vue.component(VueQrcode.name, VueQrcode)

  new Vue({
    el: '#vue',
    mixins: [windowMixin],
    data: function () {
      return {
        domain: '{{ domain.domain }}',
        domain_id: '{{ domain_id }}',
        address_id: '{{ address_id }}',
        formDialog: {
          data: {
            pubkey: null
          }
        }
      }
    },
    methods: {
      updateAddress: function () {
        var self = this
        var formDialog = this.formDialog
        var newPubKey = this.formDialog.data.pubkey

        axios
          .post(
            '/nostrnip5/api/v1/domain/' +
              this.domain_id +
              '/address/' +
              this.address_id +
              '/rotate',
            formDialog.data
          )
          .then(function (response) {
            formDialog.data = {}
            alert(
              `Success! Your pubkey has been updated. Please allow clients time to refresh the data.`
            )
          })
          .catch(function (error) {
            LNbits.utils.notifyApiError(error)
          })
      }
    }
  })
</script>
{% endblock %}
