diff --git a/apps/explorer_web/lib/explorer_web/controllers/address_qr_code_controller.ex b/apps/explorer_web/lib/explorer_web/controllers/address_qr_code_controller.ex new file mode 100644 index 0000000000..73331d7abb --- /dev/null +++ b/apps/explorer_web/lib/explorer_web/controllers/address_qr_code_controller.ex @@ -0,0 +1,7 @@ +defmodule ExplorerWeb.AddressQRCodeController do + use ExplorerWeb, :controller + + def index(conn, %{"address_id" => id}) do + send_download(conn, {:binary, QRCode.to_png(id)}, "content-type": "image/png", filename: "#{id}.png") + end +end diff --git a/apps/explorer_web/lib/explorer_web/router.ex b/apps/explorer_web/lib/explorer_web/router.ex index a5e137d319..efe52f0ba7 100644 --- a/apps/explorer_web/lib/explorer_web/router.ex +++ b/apps/explorer_web/lib/explorer_web/router.ex @@ -80,6 +80,8 @@ defmodule ExplorerWeb.Router do only: [:index], as: :contract ) + + resources("/qrcode", AddressQRCodeController, only: [:index], as: :qr_code) end get("/search", ChainController, :search) diff --git a/apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex b/apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex index 7bb248f0cf..ee5072f804 100644 --- a/apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex +++ b/apps/explorer_web/lib/explorer_web/templates/address/overview.html.eex @@ -69,7 +69,7 @@ - + <%= img_tag(address_qr_code_path(@conn, :index, @conn.assigns.locale, @address), alt: "qr_code") %>