Skip to content

About

Tezos plugin for CakePHP

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

CakeTezos

tests Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Tezos plugin for CakePHP

This plugin provides:

Install with :

composer require ziwot/cake-tezos

Load the plugin :

bin/cake plugin load CakeTezos

Link assets :

cake plugin assets symlink

You should also add it to your .gitignore :

# Plugins
/webroot/cake_tezos

Of course, when you deploy to prod, then, copy the assets :

cake plugin assets copy

Configuration

The plugin is configurable via Configure::write('CakeTezos', [...]) in your app's config/app.php:

<?php
return [
    // ...
    'CakeTezos' => [
        'defaultNetwork' => 'mainnet',

        'networks' => [
            'mainnet' => [
                'rpcUrl' => 'https://rpc.tzbeta.net',
                'tzktUrl' => 'https://api.tzkt.io',
                'networkId' => 'NetXdQprcVkpaWU',
                'label' => 'Mainnet',
            ],
            'shadownet' => [
                'rpcUrl' => 'https://rpc.shadownet.teztnets.com',
                'tzktUrl' => 'https://api.shadownet.tzkt.io',
                'networkId' => 'NetXsqzbfFenSTS',
                'label' => 'Shadownet',
            ],
            'local' => [
                'rpcUrl' => 'http://localhost:8732',
                'tzktUrl' => 'http://localhost:5000',
                'networkId' => 'NetXtJqPyJGB6Pc',
                'label' => 'Local',
            ],
        ],

        'redirect' => [
            'afterLogin' => '/',
            'afterLogout' => ['_name' => 'homepage'],
        ],

        'siwt' => [
            'statement' => 'I accept the Terms of Service',
        ],

        'cache' => [
            'balance' => [
                'enabled' => true,
                'config' => 'default',
            ],
        ],
    ],
];

You only need to specify the keys you want to override; the rest use the defaults above.

Per-element overrides

The connect element accepts statement and redirectUrl overrides:

<?= $this->element('CakeTezos.connect', [
    'statement' => 'I accept the conditions',
    'redirectUrl' => '/dashboard',
]) ?>

Authentication

Load Authenticator and Identifier :

// Load Authenticator & Identifier
$service->loadAuthenticator('CakeTezos.SignedMessage', [
    'identifier' => 'CakeTezos.TezosBase',
]);

Network Component

Load Component in (src/Controller/AppController) :

$this->loadComponent('CakeTezos.Network', [
    'network' => Network::Mainnet->value,
]);

Helpers

Load Helper in (src/View/AppView) :

$this->addHelper('CakeTezos.Tz');

Elements

⚠️ To be able to use the elements, you need to import the js module, you must add this at the top of your page :

$this->append('script', $this->Html->importmap([
    'CakeTezos' => '/cake_tezos/dist/cake-tezos.js'
]));

connect

In a view, load the element to allow connect :

<?= $this->element('CakeTezos.connect') ?>

The statement is configurable :

<?= $this->element('CakeTezos.connect', ['statement' => 'I accept the conditions']) ?>

get_metadata

<?= $this->element('CakeTezos.get_metadata', [
        'address' => $airdrop->address,
        'callBackUrl' => $this->Url->build([
            '_name' => 'admin:airdrops:edit',
            $airdrop->id
        ]),
        'csrfToken' => $this->request->getAttribute('csrfToken'),

        // js functions for UI
        'successHandler' => 'handleSuccess',
        'errorHandler' => 'handleError',
]) ?>

Development

  1. Install dependencies : composer install && npm install
  2. Build assets : npm run build

Release

Pushing to dev/main triggers build-and-distribute, which compiles assets and pushes them to the main branch. Releases are created from tags on that build branch, so the released source always contains the compiled assets.

git checkout dev/main && git pull
git checkout main && git pull
git tag v0.0.11
git push origin v0.0.11

The v* tag push triggers the Release workflow, which creates the GitHub release with auto-generated notes.

About

Tezos plugin for CakePHP

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages